文章归档

在命令 history 中显示时间戳

是一条非常实用的 shell 命令,可以显示出之前在 shell 中运行的命令,配合 last 显示之前登录的用户,就可以追溯是哪个用户执行了某些命令。

last

mysurface    tty7         :0 Mon Oct  6 20:07 – down   (00:00)
reboot   system boot  2.6.24.4-64.fc8  Mon Oct  6 20:06 (00:00)
mysurface    pts/8 10.168.28.44 Mon Oct  6 17:42 – down   (01:58)
mysurface    pts/7 :0.0 Mon Oct  6 17:4119:40 (01:59)
mysurface    pts/6 :0.0 Mon Oct  6 17:2719:40 (02:13)
mysurface    pts/5 :0.0 Mon Oct  6 17:2719:40 (02:13)
mysurface    pts/5 :0.0 Mon Oct  6 15:5215:59 (00:07)

不过默认下,history 并不记录命令的执行时间,分析起来很困难。这时候可以配置 HISTTIMEFORMAT 环境变量,给 history 记录添加上时间戳:

阅读更多 »

Share
Page 1 of 11