CDPATH in Bash

Instead of constantly typing the full path when using the cd command, BASH has a built-in feature called CDPATH. Thanks to lhunath who explained in this SO Post how to use this feature.

The first time you do this, you need to create a hidden folder and add CDPATH to your bashrc (note this step only needs to be done once):

mkdir ~/.paths
cd ~/.paths
echo 'CDPATH=~/.paths' >> ~/.bashrc

Then to add symbolic links use:

ln -s /my/very/long/path/name/to/my/project project
ln -s /some/other/very/long/path/to/my/backups backups
echo 'CDPATH=~/.paths' >> ~/.bashrc

To update your bashrc:

source ~/.bashrc

Now you can enter the folders from anywhere by simply typing

cd projects
cd backups
If you have any questions or comments, please post them below.
comments powered by Disqus