开发手册 欢迎您!
软件开发者资料库

Linux 命令(command) history

history命令是查看之前在linux中,使用过的命令的历史记录。历史命令是被保存在内存中的,当退出或者登录shell时,会自动保存或读取。在内存中,历史命令仅能够存储1000条历史命令,该数量是由环境变量HISTSIZE进行控制。本文主要是介绍history命令的选项、参数和用法以及使用实例。

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) !!:执行历史命令记录中的最后一条。

.la/js-sdk-pro.min.js">