Friday, November 9, 2007


While in a new job I finally got some time to re-read some basics, like the shell scripting and some UNIX tips and tricks. So today I re-discovered the CDPATH.

I've borrowed the following explanation from somewhere else.

The CDPATH environment variable defines additional locations to be searched when you type the cd command. When you type cd A, cd will look for A in the current directory. If you define the CDPATH environment variable which consists of a list of directories, cd will look for A in the current directory and if it is not found, the search continues in the directories defined in CDPATH, from left to right, stopping at the first place where it is found. Your working directory is then switched to A.


smol@eclipse:~$ pwd

smol@eclipse:~$ ls
foo bar
smol@eclipse:~$ ls /tmp
smol@eclipse:~$ export CDPATH=/tmp
smol@eclipse:~$ cd baz

Quite handy, something every UNIX admin likely knows already. Here is some further reading on Bash scripting features.

No comments: