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
-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 (
$ caffeinate -s scp bigfile me:myserver/bigfile
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 (via archive.org).
http://manuals.info.apple.com/en_US/ipad_user_guide.pdf --output ipad.pdf
4. DNS cache: How to clear it
Whenever a computer looks up a domain name, such as www.acme.com, 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.
- In OS X 10.4 Tiger:
$ lookupd -flushcache
- In OS X 10.5 Leopard and OS X 10.6 Snow Leopard:
$ dscacheutil -flushcache
- In OS X 10.7 Lion and OS X 10.8 Mountain Lion:
$ sudo killall -HUP mDNSResponder[and enter your password]
filetree: Show a textual file tree of subdirectories
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=". You can create the Filetree command on the spot. Below, you can see the complicated code that produces the
a bunch of commands piped together however you want"
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/-/|/'"
|---Full of Stars.app