Welcome!
Friday 03 September 2010 @ 19:08 CEST

Less typing with enviroment variable CDPATH

TechThe 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!

Trackback

Trackback URL for this entry: http://blog.larsstrand.org/trackback.php?id=CDPATH

Here's what others have to say about 'Less typing with enviroment variable CDPATH':

Shady Goings On » Less typing with environment variable CDPATH
Tracked on Monday 26 January 2009 @ 13:09 CET

Less typing with enviroment variable CDPATH | 0 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.