CDPATH is an environment variable that changes how the
cd command works. Normally when you try and cd
into a directory, it will only try and change to the path specified from the current directory. If you spend a
lot of time working in specific folders, it might be useful to assume that your search path for
cd starts from one of those folders.
For example, I spend a lot of time working in
/var/www. Instead of typing
cd /var/www/example.com all the time, I want to be able to
cd example.com and have it know what I mean. Here’s how to set that up:
Now, you can just type
cd example.com and it will look for
/var/www/example.com, stopping whenever it finds a match
or runs out of search locations.
You can have as many base search paths as you like. Here’s one that includes
/etc as a search path too.
export CDPATH=.:~:/var/www:/etc [email protected]:~$ pwd /home/vagrant [email protected]:~$ cd example.com /var/www/example.com [email protected]:/var/www/example.com$ cd mysql /etc/mysql [email protected]:/etc/mysql$ cd Downloads /home/vagrant/Downloads