Top 20 OS X command-line secrets for power users

By Mel Beckman, InfoWorld |  Software, command line, Mac OS X

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.

The opendiff command launches FileMerge to graphically compare files or directories

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]

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:

|-----kilroy

|-------Library

|---------Application Support

|-----------AddressBook

|-------------Images

|---------------CachedMacDotComPhotos

|---Full of Stars.app

|-----Contents

|-------MacOS

|-------Resources

|---------English.lproj

|-----------MacMenus.nib

|---------Sky Data


Originally published on InfoWorld |  Click here to read the original story.
Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Answers - Powered by ITworld

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Ask a Question
randomness