让history命令记录显示时间
有时候想看下什么时候执行了什么命令,一般通过histroy命令,但默认情况下history没有记录时间
# history 1 ls 2 pwd 3 ifconfig 4 clear 5 ls 6 pwd 7 cat /etc/passwd 8 history
可以设置一个HISTTIMEFORMAT环境变量,记录每条命令的执行时间
echo 'HISTTIMEFORMAT="%F %T "' >> /etc/bashrc # 注意有空格 source /etc/bashrc
再看每条命令就记录时间了
# history | head 9 2018-02-24 11:42:49 clear 10 2018-02-24 11:42:49 ifconfig 11 2018-02-24 11:42:49 ls 12 2018-02-24 11:42:49 clear 13 2018-02-24 11:42:49 ifconfig 14 2018-02-24 11:42:49 df 15 2018-02-24 11:42:49 ifconfig 16 2018-02-24 11:42:49 ssh 222.143.53.138 17 2018-02-24 11:42:49 clear 18 2018-02-24 11:42:49 yum install tcpdump -y