OS X One Liners

Posted by Walenoh on March 21, 2014

OS X one liners I have created or collected. All have been tested on Mavericks.


Kill Microsoft Excel

killall Microsoft\ Excel


This would kill the Microsoft Excel process, but what if we wanted to kill all Microsoft processes?

kill $(ps axc | grep -i Microsoft | awk '{print $1} ')

Kill all applications running from /Users folder.

ps -ef | grep /Users | awk '{print $2}' | xargs kill

Reset Printing System

lpstat -p | cut -d' ' -f2 | xargs -I{} lpadmin -x {}

Curl outside network information. Thanks to ifconfig.me

curl ifconfig.me/all

Outside IP address only

curl ifconfig.me

Display MAC Address of default interface

netstat -rn | awk '/default/ { print $NF }' | head -1 | xargs -I {} ifconfig {} | awk '/ether/ {print $2}'

List open files for a given process name

lsof -i -n -P | grep -e "$(ps aux | grep node | grep -v grep | awk -F' ' '{print $2}' | xargs | awk -F' ' '{str = $1; for(i = 2; i < NF; i++) {str = str "\\|" $i} print str}')"

Force delete of Google Chrome Google-related local storage

/bin/rm -f ~/Library/Application\ Support/Google/Chrome/Default/Local\ Storage/*google*

List OSX applications and versions

find /Applications -type d -maxdepth 1 -exec sh -c 'echo "{}"; (plutil -convert xml1 -o - "{}/Contents/Info.plist" | xpath /dev/stdin "concat(\"v\", /plist/dict/string[preceding-sibling::key[1]=\"CFBundleShortVersionString\"]/node())" 2>/dev/null)' \;

Flatten a Nested Directory & File Hierarchy

find TargetDirectory/ -mindepth 2 -type f -exec mv -i '{}' TargetDirectory/ ';'

Checking DNS records

dig walenoh.com +nostats +nocomments +nocmd

Serve current directory via Http on port 8000

python -m SimpleHTTPServer



Sources

commandlinefu.com