history命令查看执行命令的时间


Linux系统中,history命令可以显示历史命令记录。

默认情况下,history命令的输出格式为:

[zhangchuangfei@localhost ~]$ history
    1  cat /etc/centos-release
    2  uname -r
    3  poweroff
    4  bye
    5  logout
    6  ls -la
    7  history

工作中用于排查相关问题的时候,会使用history命令来查看执行命令的记录。有时候需要知道命令执行的时间,这就用到了变量HISTTIMEFORMAT。

编辑文件~/.bash_profile

[zhangchuangfei@localhost ~]$ vi .bash_profile
HISTTIMEFORMAT="%F %T "
export HISTTIMEFORMAT

使用source命令让更改立即生效

[zhangchuangfei@localhost ~]$ source .bash_profile
[zhangchuangfei@localhost ~]$ history
    1  2021-07-17 13:37:01 cat /etc/centos-release
    2  2021-07-17 13:37:01 uname -r
    3  2021-07-17 13:37:01 poweroff
    4  2021-07-17 13:37:01 bye
    5  2021-07-17 13:37:01 logout
    6  2021-07-17 13:37:13 ls -la
    7  2021-07-17 13:37:19 history
    8  2021-07-17 13:38:04 vi .bash_profile
    9  2021-07-17 13:39:32 history
   10  2021-07-17 13:40:05 vim .bash_profile
   11  2021-07-17 13:40:09 vi .bash_profile
   12  2021-07-17 13:49:35 history
   13  2021-07-17 13:49:52 source .bash_profile
   14  2021-07-17 13:49:54 history

这样再执行history命令,就可以看到命令执行的具体时间了。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM