有时候当你需要新建一个目录后,希望马上进入到这个目录中去(cd),你可以按照下面的方法去做。
# mkdir -p /tmp/subdir1/subdir2/subdir3
# cd /tmp/subdir1/subdir2/subdir3
# pwd /tmp/subdir1/subdir2/subdir3
如果将mkdir 和cd 操作在一个单独的命令中实现会不会很棒呢?试着将如下代码加入./.bash_profile 并重新登录。
$ vi .bash_profile
function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }
好了,现在看一下吧,mkdir和cd已经可以在一个命令行中实现了。
# mkdircd /tmp/subdir1/subdir2/subdir3
[注: 该命令在创建目录后并自动切换到该目录下]
# pwd
/tmp/subdir1/subdir2/subdir3
苏文龙 于 2012-07-16 14:23:49发表:
CEO, could you please explain the mean of the code in the function of mkdircd ? i just want to know why you can program like that , and it's seems very interesting to me learn this skill to operate Linux system.