history:查看命令历史(~/.bash_history,/etc/profile)
$HISTFILESIZE(缓存中):history
$HISTSIZE(磁盘文件中):在/etc/profile配置
-c:清空缓存中的历史命令
-a:缓存中的命令追加到历史文件中
-r:历史文件中的命附加到缓存中
-w:将缓存中的历史文件储存到指定的位置
num:列出倒数的num条命令
-n :只写入历史文件中没有读取过的命令到缓存(7支持)
-p:不做记录
!num:执行对应的num命令
! -1:执行倒数第一条命令
!string:执行最近以string开关的命令
!?string:执行最近包括有string的命令
!num:$:执行命令历史第num条命令的最后一个参数
229 history
230 whatis tty
231 ls /etc/centos-release
232 history
233 cat /etc/centos-release
234 history
[root@localhost ~]# ll !233:$
ll /etc/centos-release
-rw-r--r--. 1 root root 38 Apr 29 00:35 /etc/centos-release
[root@localhost ~]#
!:2:调用上次命令执行后的第二个参数
[root@localhost ~]# cat /etc/motd /etc/issue /etc/centos-release
\S
Kernel \r on an \m
CentOS Linux release 7.5.1804 (Core)
[root@localhost ~]# ll !:2
ll /etc/issue
-rw-r--r--. 1 root root 23 Apr 29 00:35 /etc/issue
- c :清除内存中的历史
•
重复前一个命令,有4种方法
–
重复前一个命令使用上方向键,并回车执行
–
按!! 并回车执行
–
输入!-1 并回车执行
–
按Ctrl+p并回车执行
•
!:0 执行前一条命令(去除参数)
•
Ctrl + n 显示当前历史中的下一条命令,但不执行
•
Ctrl + j 执行当前命令
•
!n 执行history命令输出对应序号n的命令
•
!-n 执行history历史中倒数第n个命令
•
!string 重复前一个以“string”开头的命令
•
!?string 重复前一个包含string的命令
•
!command:p仅打印命令历史,而不执行
•
!$:p 打印输出!$ (上一条命令的最后一个参数)的内容
•
!*:p打印输出!*(上一条命令的所有参数)的内容
•
^string删除上一条命令中的第一个string
•
^string1^string2将上一条命令中的第一个string1替换为string2
•
!:gs/string1/string2将上一条命令中所有的string1都替换为string2