You want to make it easier to switch between several directories in various locations.
Set your $CDPATH appropriately. Your commonly used directories will likely be unique, so for a contrived example, suppose you spend a lot of time working with init’s rc directories:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/home/jp$ cd rc3.d bash: cd: rc3.d: No such file or directory /home/jp$ export CDPATH='.:/etc' /home/jp$ cd rc3.d /etc/rc3.d /etc/rc3.d$ cd rc5.d /etc/rc5.d /etc/rc5.d$ /etc/rc5.d$ cd games bash: cd: games: No such file or directory /etc/rc5.d$ export CDPATH='.:/etc:/usr' /etc/rc5.d$ cd games /usr/games /usr/games$ |
According to the bash Reference, $CDPATH is “a colon-separated list of directories used as a search path for the cd built-in command.”
Think of it as $PATH for cd. It’s a little subtle, but can be very handy.
If the argument to cd begins with a slash, $CDPATH will not be used. If $CDPATH is used,
the absolute pathname to the new directory is printed to STDOUT, as in the example above.