Mac OSX Command Line Notes

To flush DNS cache:

sudo dscacheutil -flushcache

To mount a DMG:

hdiutil attach ‘/path/to/dmg’

To install a .pkg or .mpkg

sudo installer -pkg ‘/path/to/pkg’ -target /

To unset the “locked” flag on files (usually copied as read-only from another system):

chflags nouchg [file name]

To use find and xargs to do interesting things to LARGE lists of files (“xxx” can be any unique sequence of characters. ┬áMost online examples use … -I “{}” …):

find . -name *.txt | xargs –Ixxx rm xxx

To get a quick count of files in a directory/diretories without counting meta files (files/folders that start with “.”):

ls | wc -l

To en|disable Spotlight in Mac OSX:

sudo mdutil -a -i off|on

To remove the menu bar icon:

sudo chmod 600 /System/Library/CoreServices/Search.bundle/Contents/MacOS/Search

killall SystemUIServer