Vincent Gable’s Blog

February 28, 2008

Useful MacOSX Terminal Commands

Filed under: MacOSX,Tips,UNIX | , ,
― Vincent Gable on February 28, 2008

Here are some OS X specific terminal commands that I have found useful, and you might not be aware of. Running man command in the Terminal will give you more information about command as it is on your system.

open
open file will open file the same way it would have been opened if you double-clicked it in the Finder. You can also specify what program to use to open the file.

pbcopy, pbpaste
Bridges the clipboard and the command line; you can pipe the clipboard into stdout, or pipe stdout into the clipboard.

ps -axww
Lists every process running on the system, and gives the full-path to them, and their PSN. I almost never use any other arguments to ps.

osascript
Execute an AppleScript. osascript -e “code-goes-here”, will execute the AppleScript inside the “”. This is a great way to get AppleScript functionality in a good scripting language.

ditto
Can do the work of cp or zip, but it does the right thing on OS X, and won’t throw away Mac-specific bits.
ditto -ckX --rsrc --keepParent path_to_a_bundledFile.bundle bundledFile.bundle.zip will compress path_to_a_bundledFile.bundle, and keep all the Mac-bits intact.

hdiutil
Create and manipulate disk-images; you can even use it to burn a disk-image to CD/DVD.
Inside a perl-script I do:
hdiutil create -ov -fs HFS+ -format UDBZ -volname \”IMLocation v$version (beta)\” -srcfolder $IMLBuildDir ~/Projects/Website/imlocation/IMLocation.dmg

To make the disk-image for IMLocation out of the contents of the directory $IMLBuildDir.

screencapture
Lets you take a screenshot. Unfortunately not very well documented.
screencapture -x /tmp/screen.png
Will silently take a screenshot, and save it to /tmp/screen.png.
I think this could be great for bug-reporting.

system_profiler
Reports system hardware and software configuration; with no arguments it reports everything. Obviously great for bug reports and research.

sw_vers
Prints version information about the Mac OS X.
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.5
BuildVersion: 9A581
$ sw_vers -productName
Mac OS X
$ sw_vers -productVersion
10.5
$ sw_vers -buildVersion
9A581

systemsetup
Configuration tool for certain machine settings in System Preferences.

defaults
Read and write application preferences. You can use it to discover and activate hidden settings, like Safari’s Debug menu. defaults read > all_defaults.txt will give you a grep-able text-file with every default on your system. It’s also a useful tool for automated testing, since you can twiddle configurations.

class-dump (3rd party tool)
Makes .h files from a binary. Great for reverse-engineering.

In addition to standard UNIX commands, Mac OS X includes many powerful command-line tools. This article only scratches the surface, and ignores many tools like podcast that are probably very useful, but aren’t part of my workflow.

1 Comment »

  1. For buffing up on general UNIX command line wizardry, you might try browsing commandlinefu.com by score.

    Comment by Vincent Gable — March 23, 2009 @ 5:19 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress