history bash 命令可以查看bash中输入的命令行的“历史”,即记录的意思
我一般是这样使用的
1.history 列出所以敲过的bash命令
2.history n 列出第几个敲过的命令
3.!history 执行上一条执行的命令,其实用上下键切换回上一条命令回车,岂不是更方便,但是这条命令“!history”不会被写入“历史”中去
那更多的history命令怎么来使用?还是帮助文档。
man history 1
An event designator is a reference to a command line entry in the history list.
! Start a history substitution, except when followed by a blank, newline, = or (.
!n Refer to command line n.
!-n Refer to the current command line minus n.
!! Refer to the previous command. This is a synonym for `!-1'.
!string
Refer to the most recent command starting with string.
!?string[?]
Refer to the most recent command containing string. The trailing ? may be omitted if string is followed
immediately by a newline.
^string1^string2^
Quick substitution. Repeat the last command, replacing string1 with string2. Equivalent to
``!!:s/string1/string2/'' (see Modifiers below).
!# The entire command line typed so far.
那看看我们还能使用哪些命令
4. !n 执行历史中的第n条命令
其他的 在以后使用中在补充出来
除了这些,我们还可以在这个记录文件中查看历史
vi ~.bash_history
可以查出历史中都输入了些什么命令行
ok,再来补充一下
!-n 执行命令行历史后退n条的指令
!! 等价于!-1