25 Terminal Tips Every Mac User Should Know
Posted 12/11/2008 at 11:40am
| by Johnathon Williams

One of the reasons we use Macs is how self-sufficient OS X tends to be. Most of the time, system maintenance occurs in the background, and mundane tasks that do require user participation (backups, for instance) are made as painless as possible (thank you, Time Machine.) For those times when we want or need more system-level control, these are the Terminal commands to rely on.
22. Backup In A Snap

Rsync has far too many options to mention. Execute man rsync for the full list.
In any article about the Terminal, federal law requires us to mention rsync, the only backup utility you really need. Rsync can create full bootable backups of your entire hard drive or any combination of folders. On subsequent backups, it’s smart enough to copy only those files that have changed, saving a lot of time. Indeed, rsync is so powerful and flexible that many graphical backup utilities are little more than shiny wrappers that call rsync in the background.
To back up your entire Home folder, execute rsync -auE --progress ~ /Volumes/name-of-drive/name-of-backup-folder.
Replace the placeholders after the last two slashes with the name of your drive and backup folder, respectively. To back up your entire startup drive, run sudo rsync -auE --progress / /Volumes/name-of-drive/name-of-backup-folder.
23. Identify And Eliminate A Memory Hog

Take out your aggression on misbehaving processes with the kill command.
When sluggish performance slows your desktop to a crawl, a runaway application might be the culprit. Check CPU and memory usage in all open applications by executing top. The command returns a list of every running process our your Mac, along with its allocated resources. The CPU field is easy enough to interpret--any process using more than half is sure to slow others down. The memory fields are a bit more complicated but, in general, the bigger the numbers, the greater the drain on your system.
If the problem app is visible on the Desktop, quit it as you normally would, using Command-Q or, if that fails to respond, using Force Quit (Command-Option-Escape).
But if the culprit is a lower-lever utility that runs behind the scenes, you’ll need more Terminal magic to end its misadventures. Make note of the problem process’s number in the PID column, and execute sudo kill PID-number, replacing PID-number with the application’s actual number. The targeted process will terminate, freeing up its system resources.
Be extremely careful when killing background processes. Some are necessary for OS X to function. Ideally, you would only use kill if you were absolutely certain that a third-party background utility was slowing you down.
24. Find Free Space On All Your Hard Drives

You might find you have a lot more—or a lot less—free space on your drives than you thought.
At last count, our primary Mac was spread between three different hard drives--one internal for the OS and essential documents, and two externals for our photos, movies, and music. In this kind of setup, it can be difficult to know at a glance just how much free space you have left--and where, exactly, it is.
To see your free space, execute df -hl.
25. Snap superior screenshots

Forget OS X’s built-in Grab utility. Snap a picture of whatever’s displaying onscreen and select the image file’s format and name with one Terminal command.
If OS X’s default screenshot settings don’t meet your needs, you can assign image formats and file names for screenshots on the fly with screencapture, which lets you take shots of DVD Player (usually forbidden by the Finder at the insistence of the movie industry’s copyright lawyers). To create an instant, noiseless capture, execute screencapture -x -t jpg capture.jpg.
Replace jpg with the 3-digit abbreviation for your chosen file format (PDF, TIF, GIF, and PNG are also available) and capture.jpg is the name of the saved file.