The BASH shell has several environment variables that can be manipulated. The PATH variable is well known. Another useful variable is CDPATH. As PATH is a list of search paths for commands, so is CDPATH a list of directories used as search path for the "cd" command.
Example: At one ftp server we serve a lot of software, including several of the most popular Linux distributions. The local path to these distributions involves a lot of typing:
larsks@spheniscus:~$ cd /usit/spheniscus/ftp/linux/
larsks@spheniscus:/usit/spheniscus/ftp/linux$
From here, I can jump into "slackware/", "centos/", "debian/" and so on. But it's simpler when using CDPATH:
larsks@spheniscus:~$ export CDPATH="/usit/spheniscus/ftp/linux"
larsks@spheniscus:~$ cd slackware
/usit/spheniscus/ftp/linux/slackware
larsks@spheniscus:/usit/spheniscus/ftp/linux/slackware$
Nice huh?
An even lazier method (involving less typing) is to use alias:
larsks@spheniscus:~$ alias s="cd /usit/spheniscus/ftp/linux/slackware"
larsks@spheniscus:~$ s
larsks@spheniscus:/usit/spheniscus/ftp/linux/slackware$
But then I have to create one alias for each directory. Oh the choices!
No comments:
Post a Comment