Top 20 OS X command-line secrets for power users

Beyond Bash: The most useful command-line utilities for Mac power users and system administrators

1 2 3 4 5 6 Page 2
Page 2 of 6

2. caffeinate: Prevent a system from sleeping
This command is new in OS X Mountan Lion. Let's say you started a long-running file transfer just before lunch and don't want your system to go to sleep. What do you do? Give it some caffeine! That's what caffeinate does. You can explicitly specify an elapsed period of wakefullness, in seconds, with the -u and -t options, or you can use caffeinate to invoke a command-line utility that you want to not be interrupted by sleep.

To prevent your Mac from sleeping for one hour (3,600 seconds):
$ caffeinate -u -t 3600

To prevent your Mac from sleeping until the secure file copy (scp) completes:
$ caffeinate -s scp bigfile me:myserver/bigfile

3. curl: Download a URL from the command line (copy URL)
A powerhouse of a command-line utility, curl lets you do many things, but the most handy capability is retrieving a file from a website. Just pass the URL to curl and tell it where to deliver the load via the --output option, as demonstrated below. You'll find curl can rename the file at the same time, or it can download entire website directories -- recursively, even. Copy the entire Internet if you want. The U.S. government does (
$ curl --output ipad.pdf

4. DNS cache: How to clear it
Whenever a computer looks up a domain name, such as, it caches the answer so that all future requests can be satisfied without performing the entire DNS lookup process. But sometimes you want to clear this cache to force the DNS lookup to occur again, such as when the IP address for a particular domain name changes. OS X has three ways to do this, shown below, depending on which version of OS X you're running.

Note that for Lion and Mountain Lion, clearing the DNS cache requires administrative privileges and the sudo (Superuser Do) enabler.

5. filetree: Show a textual file tree of subdirectories
The filetree command is wonderful. It prints out a nice text tree showing all the directories subsidiary to the directory your command line is currently in.

The only problem with this command: It doesn't exist. Fortunately, one of the wonders of Bash is that you can make your own commands, using Bash's alias function (thank you, Brian). Just type alias nameyourcommand="a bunch of commands piped together however you want". You can create the Filetree command on the spot. Below, you can see the complicated code that produces the filetree output. I have no idea how it works, and I don't care. Just let me type filetree instead of that crazy command line.

Note that just creating an alias doesn't make it permanent. When you close the Terminal window, all your command aliases go away. To "remember" them from session to session, you have to add them to the hidden .profile file in your home directory. You can edit that using the open command described in command-line utility No. 9 later in this article (that is, open -e ~/.profile):
$ alias filetree="ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'"
$ filetree

Sample results:
|---------Application Support
|---Full of
|---------Sky Data
|-----------Ambient Audio

1 2 3 4 5 6 Page 2
Page 2 of 6
How to choose a low-code development platform