Friday, 25 September 2009

Handy OSX commands

List USB devices (a bit like lsusb on Linux)
On standard installation:
ioreg -c IOUSBDevice -l -w 0
Or using the developer tools:

Airport Wifi Info
There are various arguments you can run it with -h to get a listing but the most useful are -I to get current wireless status, and -s to do a wireless scan.

Mount and mess with disk images
Here's how to mount a dmg:
hdiutil attach your_disk_image.dmg

List process' network connections
sudo lsof -i -P

Tweaking startup apps
- To disable startup items - add/rm a file called .disabled in their directory (i.e. a subdir of /System/Library/StartupItems/ or /System/Library/StartupItems/)
- launchctl -- Interfaces with launchd - in /Library/LaunchDaemons and similar
- Various custom ones; e.g. sudo "/Library/Application Support/VMware Fusion/" --stop

Search using Spotlight on the command line
mdfind your_search_term (or mdfind -name file_to_find to look for file names).
There's also a few other related utilities like mdls to list file attributes etc. For more info see this useful post. It is also possible to enable the unix style locate command but it seems like a waste of space on OSX since you've already got Spotlight - though locate does provide for searching all files (only by name). However one can tweak Spotlight to search these files too...

Playing sounds on the cmd line
Also afinfo gives you info on the file.

Print out OSX version
/usr/bin/sw_vers | grep 'ProductVersion:' | grep -o '[0-9]*\.[0-9]*\.[0-9]*'
Or use system profiler (both suggestions from here):
system_profiler SPSoftwareDataType

There's also other pages with similarly useful info like here.

[updated: 23mar10]