Hack 1. Use CDPATH to define the base directory for cd command
by Ramesh
If you are frequently performing cd to subdirectories of a specific parent directory, you can set the CDPATH to the parent directory and perform cd to the subdirectories without giving the parent directory path as explained below.
- [ramesh@dev-db ~]# pwd
- /home/ramesh
- [ramesh@dev-db ~]# cd mail
- -bash: cd: mail: No such file or directory
- [Note: This is looking for mail directory under current directory]
- [ramesh@dev-db ~]# export CDPATH=/etc
- [ramesh@dev-db ~]# cd mail
- /etc/mail
- [Note: This is looking for mail under /etc and not under current directory]
- [ramesh@dev-db /etc/mail]# pwd
- /etc/mail
To make this change permanent, add export CDPATH=/etc to your ~/.bash_profile
Similar to the PATH variable, you can add more than one directory entry in the CDPATH variable, separating them with : , as shown below.
- $ export CDPATH=.:~:/etc:/var
This hack can be very helpful under the following situations:
- Oracle DBAs frequently working under $ORACLE_HOME, can set the CDPATH variable to the oracle home
- Unix sysadmins frequently working under /etc, can set the CDPATH variable to /etc
- Developers frequently working under project directory /home/projects, can set the CDPATH variable to /home/projects
- End-users frequently accessing the subdirectories under their home directory, can set the CDPATH variable to ~ (home directory)
当前内容版权归 Ramesh Natarajan 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 Ramesh Natarajan .