
46
|
Chapter 2, Console
#14 Simplify Changing Directories
HACK
HACK
#14
Simplify Changing Directories Hack #14
This hack makes it ridiculously easy to jump right to your favorite directories
from the command line.
Every Linux user probably knows there’s an environment variable called
PATH. When you type a command, your system looks through all the directo-
ries defined in the
PATH environment variable until it finds the command. If it
doesn’t find the command by the time it has exhausted all the directories
listed in the path, it tells you it can’t find the file.
There’s a similar environment variable that is a bit more obscure called
CDPATH. You can define CDPATH to include a number of directories to search
when you type the following command:
$ cd somewhere
Here’s how it works. Assume for a moment that you’re an obsessively orga-
nized writer who likes to create directory trees that organize files by types,
groups, categories, etc. Let’s say you organized your documents such that
you have the following directories:
/docs/pub/books/oreilly/linuxhacks/chapter1
/docs/pub/books/oreilly/linuxhacks/chapter2
/docs/pub/books/oreilly/linuxhacks/chapter3
Here’s what you want to do. You want to be able to jump right to the
chapter2 directory without having to type the entire path. Here’s how to set
the
CDPATH environment variable so that you can do that:
$ export CDPATH=:.:/docs/pub/books/oreilly/linuxhacks
Notice