Pages

Monday, March 5, 2012

Using CDPATH

Share it Please

We are already aware of the PATH variables in linux.The locations specified in the PATH are searched for something it that is not currently found in the current directory. Linux also supports CDPATH which provides directories to look when cd command changes to other locations like

[root@vx111a ~]# export CDPATH=/etc
[root@vx111a ~]# cd mail
/etc/mail
[root@vx111a mail]# pwd
/etc/mail
[root@vx111a mail]# cd -
/root
[root@vx111a ~]# pwd
/root
[root@vx111a ~]# export CDPATH=.:/etc:/var
[root@vx111a ~]# cd ftp
/var/ftp

Check then whenever we enter cd mail, it automatically takes us to the /etc/mail, But one thing we need to keep in mind is if we have a same directory with the same name as mail, even then it automatically takes us to the /etc/mail. In that case we need to add cd ./mail to go to mail directory in our current location. We can add the CDPATH to the .bashrc file with multiple directory locations and move between directories faster.

1 comment :