CDPATH
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
just type cd example.com
and have it know what I mean. Here's how to set that up:
bash
export CDPATH=.:~:/var/www
Now, you can just type cd example.com
and it will look for ./example.com
then /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.
bash
export CDPATH=.:~:/var/www:/etcvagrant@precise64:~$ pwd/home/vagrantvagrant@precise64:~$ cd example.com/var/www/example.comvagrant@precise64:/var/www/example.com$ cd mysql/etc/mysqlvagrant@precise64:/etc/mysql$ cd Downloads/home/vagrant/Downloads