Saturday, July 7, 2007

cd to Directory within Terminal

When using terminal, if you need to drill down to different directories, you don't need to type the entire path. You can use tab key to expand file/directory names. For instance if I type cd P and tab, it expands P to Presentations which is a directory I have under my current directory. If there is more than one file or directory that starts with a P, then it lists them all so I can be more specific.

I discovered by accident a related feature. If you hit escape before hitting the tab, it expands all the way to the most recently navigated directory (from your history) that matches what you've entered. For example, since I use Parallels, I have a need to navigate to ~/Documents/Parallels/shared directory on my mac to exchange some files with my Windows Vista (As of this week, I will need this less on recent Parallels 3.0 since the Windows directory is fully exported/mounted on the mac!). I could type cd ~/D and tab, and then P and tab, and then s and tab. Instead, when I type cd ~/ and escape and tab, it expanded straight to cd ~/Documents/Parallels/shared. Very convenient.

One last thing. If you want to open a terminal on any directory, there is a easy Quicksilver way to do that as well.

Go to Quicksilver (ctrl + q on my machine).
Start with the home directory and type first letter or two of the directory you're interested and type forward slash to drill down to that directory in Quicksilver. For example, to go to ~/Documents/Parallels/shared, I type the following characters in sequence ~d/p/s followed by a tab to select an Action in Quicksilver. For the action, type t and it brings up "Go To Directory in Terminal." Hit return and it opens the directory in terminal window.

Related Posts:

The QuickSilver Files: Grabbing the Universe

The QuickSilver Files: Quick Folders and Select All

The Quicksilver Files: Triggers

1 comment:

Edward said...

These are really bash features more than OS X, but I should also add one of my faves:

ctrl-r is "find as you type history", which is tons better than grepping through your history or hitting up and down in the shell for a while.

If there's two entries that match, you can keep hitting ctrl-r to find the one you're looking for.