How can I save the path to a frequently used directory in UNIX? How can I save the path to a frequently used directory in UNIX? unix unix

How can I save the path to a frequently used directory in UNIX?


Define your favorite directories in CDPATH environment variable. It's a colon-separated list of search paths available to the cd command. You should specify not a directory you want to switch but parent directory.

Here is brief info about it: http://docstore.mik.ua/orelly/unix/upt/ch14_05.htm

For example you have three directories you work with frequently:

/home/user/scripts/favorite//var/log//var/lib/

add to your ~/.bash_profile (or another shell profile file you use) the next line:

export CDPATH=.:/home/user/scripts:/var

In the example below I just redefine CDPATH in shell for the current session

[user@server lib]$ CDPATH=.:/var:/home/user/scripts[user@server lib]$ cd log/var/log[user@server log]$ cd lib/var/lib[user@server lib]$ cd favorite/home/user/scripts/favorite

If you want use tab while execute cd you can install bash-completion http://bash-completion.alioth.debian.org/ but it's optional

Also do not forget cd - command for quick switching to previous working dir


You can always add the directory path in ~/.bashrc

vi ~/.bashrc

export FAV_DIR1=''

The variables in .bashrc load into the environment on new session. So make sure to reboot.

Then you can visit the directory by something like:

cd $FAV_DIR1