Shell tricks: directory browsing
Scott from The Open Source Weblog found a couple of neat little scripts for moving around directories over at the Linux Gazette the other day; I thought I'd share them with you, since they work just as well in the OS X Terminal.
First, dn is a command to display the directories below your current location in a numbered table.
At the command line, type:
alias dn='OPTIONS=$(ls -F |grep /$); \ select s in $OPTIONS; do cd $PWD/$s ; \ break ; done'
If you're not familiar with the Terminal, you can also type that all on one line, without the backslashes. You can also put this script into your .bashrc file to have it available every time you open the terminal.
Now, when you type dn at the command line, you should see something like the following:
jsavage@ariadne:~> dn 1) Geo-PostalCode-0.06/ 2) ljpc-0.91/ 3) lost+found/ 4) mlatex/ #?
Just type the number of the directory you want at the question mark, and off you go!
dnf is similar, but will show you hidden directories as well:
alias dnf='OPTIONS=$(ls -aF |grep /$) ; \ select s in $OPTIONS; do cd $PWD/$s ; \ break ; done'
Neither of these is a complicated script; they're both just wrappers for the standard unix ls command. They are, however, extremely useful.