Bash: Shortcuts to your favorite directories with CDPATH

This is a fairly handy trick.
I’m always logging in to different servers, which all have a different location for their logs. With this trick you can login and just type “cd logs” from anywhere.
First we will add our directory to the CDPATH variable:
[code language=”Bash”]
joris@badattitude /data/share/my_domain
$ echo $CDPATH
joris@badattitude /data/share/my_domain
$ export CDPATH=/data/share/my_domain
joris@badattitude /data/share/my_domain
$ echo $CDPATH
/data/share/my_domain
[/code]
Then we’ll check if it is working:
[code language=”Bash”]
joris@badattitude ~
$ cd logs
/data/share/my_domain/logs
joris@badattitude /data/share/my_domain/logs
$
[/code]
Awesome, we’ve arrived in our logs directory straight from our homedir!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.