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 里添加下面的参数:
|
|
本文介绍如何在Bash环境中为历史命令添加时间戳,包括使用HISTTIMEFORMAT变量及实时写入history的方法。
1181

被折叠的 条评论
为什么被折叠?



