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.
Example:
smol@eclipse:~$ pwd
/home/smol
smol@eclipse:~$ ls
foo bar
smol@eclipse:~$ ls /tmp
baz
smol@eclipse:~$ export CDPATH=/tmp
smol@eclipse:~$ cd baz
/tmp/baz
smol@eclipse:/tmp/baz$
Quite handy, something every UNIX admin likely knows already. Here is some further reading on Bash scripting features.
No comments:
Post a Comment