1、使用语法:history (选项) (参数)
1)选项
-c:清空当前历史命令;
-a:将历史命令缓冲区中命令写入历史命令文件中;
-r:将历史命令文件中的命令读入当前历史命令缓冲区;
-w:将当前历史命令缓冲区命令写入历史命令文件中。
2)参数
n:打印最近的n条历史命令。
3)常用实例:
显示最近10条历史命令
[root@linux ~]# history 10
69 ls -al
70 cd linux
71 ls -al
72 cd ..
73 ls -al
74 ssh root@192.168.31.55
75 ssh root@192.168.31.11
76 git
77 python
78 history 10
清空历史命令
[root@linux ~]# history -c
将当前或所有历史命令缓冲区中命令立即写入文件(~/.bash_history),也可以自己指定文件。
[root@linux ~]# history -w 或 [root@linux ~]# history -w histfiles
[root@linux ~]# history -a 或 [root@linux ~]# history -a histfiles
可以将之前保存的历史命令的文件读到缓冲区
[root@linux ~]# history -r 或 [root@linux ~]# history -r histfiles
2.执行历史记录中的命令
1) !number:执行历史命令记录中第number条命令。
2) !commandstr:在历史记录中搜索最近一条与commandstr相匹配的命令执行。
3) !!:执行历史命令记录中的最后一条。