[Linux]常用命令之【history】#查看历史操作#

1 历史记录: history

history命令就是历史记录。
它显示了在终端中所执行过的所有命令的历史。

history       //显示终端执行过的命令
history 10  //显示最近10条终端执行过的命令
Ctrl+r        //搜索已经执行过的命令,它可以你写命令时自动补全

2 历史记录(history): 保存位置

~/.bash_history

3 修改/配置: history命令

vi ~/.bash_profile
 HISTFILESIZE=2000     //定义了在文件 ~/.bash_history 中保存命令的记录总数
 HISTSIZE=2000         //定义history 命令输出的记录数

 HISTTIMEFORMAT="%Y-%m-%d:%H-%M-%S:`whoami`:  "    //记录每条历史命令的执行时间和执行者,显示结果为21  2019-02-16:09-06-01:edwetl:  vi .profile
 HISTTIMEFORMAT='<%F %T> : '   //显示结果为  21  <2019-02-16 09:06:01> : vi .profile

4 history 命令用法

清除历史记录

[root@localhost root]# history -c  
  // 清空历史执行命令 (20220402 亲测)

[root@localhost root]# echo > ./.bash_history   
  // 或清空用户目录下的这个文件即可

导入历史记录

[root@localhost root]# vi /root/history   
  // 新建记录文件

[root@localhost root]# history -c   
  // 清除记录 

[root@localhost root]# history -r /root/history.txt   
  // 导入记录 

[root@localhost root]# history   
  // 查询导入结果

X 参考与推荐文献

posted @ 2020-10-25 18:53  千千寰宇  阅读(855)  评论(0编辑  收藏  举报