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/ all the time, I want to be able to
just type cd and have it know what I mean. Here’s how to set that up:

export CDPATH=.:~:/var/www

Now, you can just type cd and it will look for ./ then /var/www/, 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

[email protected]:~$ cd

[email protected]:/var/www/$ cd mysql

[email protected]:/etc/mysql$ cd Downloads
Michael is a polyglot software engineer, committed to reducing complexity in systems and making them more predictable. Working with a variety of languages and tools, he shares his technical expertise to audiences all around the world at user groups and conferences. You can follow @mheap on Twitter

Thoughts on this post

Leave a comment?

Leave a Reply