让linux history命令显示命令的执行时间、在哪个机器执行的这个命令

简介:


1.在/etc/profile的最后添加如下部分:

USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`  

export HISTTIMEFORMAT="[%F %T][`whoami`][${USER_IP}] " 

2. source /etc/profile

3.随便执行一下什么命令,

4.执行history,看效果:

  311  [2013-08-28 14:39:20][root][192.168.80.1] history

  312  [2013-08-28 14:39:43][root][192.168.80.1] df -h

  313  [2013-08-28 14:39:45][root][192.168.80.1] df -g

  314  [2013-08-28 14:39:47][root][192.168.80.1] history

  315  [2013-08-28 14:40:01][root][192.168.80.1] ifconfig

  316  [2013-08-28 14:44:53][root][192.168.80.1] init 6

  317  [2013-08-28 14:46:56][root][192.168.80.1] sdfsdfsd

  318  [2013-08-28 14:46:58][root][192.168.80.1] ls

  319  [2013-08-28 14:47:02][root][192.168.80.1] hostory

  320  [2013-08-28 14:47:04][root][192.168.80.1] history

  321  [2013-08-28 14:48:35][root][192.168.80.1] cat /etc/profile

  322  [2013-08-28 14:54:32][root][192.168.80.1] history

注意:1和2必须先执行完之后,才能看到history的效果。若是想看1个月前的history,而那时还没有执行1和2,这种情况下是看不到想要的效果的。


     本文转自yzy121403725 51CTO博客,原文链接:http://blog.51cto.com/lookingdream/1842334,如需转载请自行联系原作者





相关文章
|
1天前
|
监控 Linux Windows
50个必知的Linux命令技巧,你都掌握了吗?(下)
50个必知的Linux命令技巧,你都掌握了吗?(下)
|
1天前
|
Linux Shell Windows
Linux 常用基本命令
Linux 常用基本命令
|
2天前
|
Ubuntu Linux Shell
linux免交互登陆远程主机并执行命令(密钥对和Expect)
linux免交互登陆远程主机并执行命令(密钥对和Expect)
|
2天前
|
Linux
【Linux】常用命令
【Linux】常用命令
21 0
|
2天前
|
安全 Ubuntu Linux
Linux 网络操作命令Telnet
Linux 网络操作命令Telnet
16 0
Linux 网络操作命令Telnet
|
3天前
|
Linux 数据安全/隐私保护
Linux常用命令实例带注释
Linux常用命令实例带注释
30 0
|
3天前
|
Linux 开发工具 数据安全/隐私保护
Linux(19)常用解压命令记录
Linux(19)常用解压命令记录
9 0
|
6月前
|
Linux
Linux命令之history
Linux命令 history
126 0
|
8月前
|
Shell Linux 开发工具
10.3.2 【Linux】历史命令:history
10.3.2 【Linux】历史命令:history
92 0