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