时间长了不用都忘了, 还是记一下吧~
cd - #回到上次所在目录,这个技巧我原来还真是不知道,感觉还是比较有用,省略了很多输入。
cd !$ #把上个命令的最后一个参数作为输入。
cd #回到主目录
cd ~ #同样也是回到主目录
另外, 为什么!$能达到上面所述的效果呢.
原因可以Mendel Cooper的参考这个链接
Advanced Bash-Scripting Guide => An in-depth exploration of the art of shell scripting
里面这样介绍 !
!
reverse (or negate) the sense of a test or exit status [bang]. The ! operator inverts the exit status of the command to which it is applied (see Example 6-2). It also inverts the meaning of a test operator. This can, for example, change the sense of equal ( = ) to not-equal ( != ). The ! operator is a Bash keyword.
In a different context, the ! also appears in indirect variable references.
In yet another context, from the command line, the ! invokes the Bash history mechanism (see Appendix L). Note that within a script, the history mechanism is disabled.
reverse (or negate) the sense of a test or exit status [bang]. The ! operator inverts the exit status of the command to which it is applied (see Example 6-2). It also inverts the meaning of a test operator. This can, for example, change the sense of equal ( = ) to not-equal ( != ). The ! operator is a Bash keyword.
In a different context, the ! also appears in indirect variable references.
In yet another context, from the command line, the ! invokes the Bash history mechanism (see Appendix L). Note that within a script, the history mechanism is disabled.
关于使用!去引用bash history的详细链接如下:
里面还有!的其他用法, 需要的自行参考吧.
http://tldp.org/LDP/abs/html/abs-guide.html#HISTCOMMANDS