在bash中,所执行的命令可以用history显示出来,但是bash的机制是:先将命令写入baffer,退出shell时才会写入.bash_history文件中,所以最后.bash_history文件中的命令无法分辨出来时间,解决这个问题可以采用时间戳的方法。
bash中提供了时间戳的参数HISTTIMEFORMAT
有了这个参数,可以让执行的命令用history显示时,前面加上时间戳。举例如下:
另外就是需要让bash实时写入历史命令。在 /etc/profile 里添加下面的参数:
bash中提供了时间戳的参数HISTTIMEFORMAT
|
有了这个参数,可以让执行的命令用history显示时,前面加上时间戳。举例如下:
1011 root 192.168.1.119 2011-03-12 14:49:43 cd / 1012 root 192.168.1.119 2011-03-12 14:49:45 ls 1013 root 192.168.1.119 2011-03-12 14:49:53 vi /etc/profile 1014 root 192.168.1.119 2011-03-12 14:49:59 vi /etc/hosts 1015 root 192.168.1.119 2011-03-12 14:50:12 vi /etc/resolv.conf 1016 root 192.168.1.119 2011-03-12 14:50:15 history 1017 root 192.168.1.119 2011-03-12 14:51:23 cat /etc/profile 1018 root 192.168.1.119 2011-03-12 14:51:30 cat /etc/hosts 1019 root 192.168.1.119 2011-03-12 14:51:35 cat /etc/hosts.allow 1020 root 192.168.1.119 2011-03-12 14:51:39 cat /etc/hosts.deny 1021 root 192.168.1.119 2011-03-12 14:51:48 cat /etc/resolv.conf 1022 root 192.168.1.119 2011-03-12 14:51:51 history |
另外就是需要让bash实时写入历史命令。在 /etc/profile 里添加下面的参数:
|