Chinaunix首页 | 论坛 | 博客
  • 博客访问: 265251
  • 博文数量: 74
  • 博客积分: 1470
  • 博客等级: 上尉
  • 技术积分: 793
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-25 21:01
文章分类

全部博文(74)

文章存档

2011年(1)

2010年(32)

2009年(32)

2008年(9)

我的朋友

分类: LINUX

2009-10-06 19:16:03

  • Use CDPATH to define the base directory for cd command
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
  • Use cd alias to navigate up the directory effectively
When you are navigating up a very long directory structure, you may be using cd ..\..\ with multiple ..\’s depending on how many directories you want to go up as shown below.

# mkdir -p /tmp/very/long/directory/structure/that/is/too/deep
# cd /tmp/very/long/directory/structure/that/is/too/deep
# pwd
/tmp/very/long/directory/structure/that/is/too/deep
# cd ../../../../
# pwd
/tmp/very/long/directory/structure


Instead of executing cd ../../../.. to navigate four levels up, use one of the following alias methods:alias cd1="cd .."

alias cd2="cd ../.."
alias cd3="cd ../../.."
alias cd4="cd ../../../.."
alias cd5="cd ../../../../.."

add these alias to your ~/.bashrc and source it
  • Use “shopt -s cdspell” to automatically correct mistyped directory names on cd
Use shopt -s cdspell to correct the typos in the cd command automatically as shown below. If you are not good at typing and make lot of mistakes, this will be very helpful.

# cd /etc/mall
-bash: cd: /etc/mall: No such file or directory
# shopt -s cdspell
# cd /etc/mall
# pwd
/etc/mail
[Note: By mistake, when I typed mall instead of mail,cd corrected it automatically]



reference:



阅读(828) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~