这个需要使用到history命令。可以加数字,返回最近执行的几条命令。如果不加数字会返回所有的历史命令。
[root@localhost ~]# history 20
1015rm stdin.log1016ll1017rm yy1018ll1019 echo 'hello' 1>>echo.log1020ll1021cat echo.log1022 echo 'world' 1>>echo.log1023cat echo.log1024 echo 'world' 1>echo.log1025cat echo.log1026ll1027rm echo.log1028last1029history1030who am i1031clear1032history1033*
1034 history 20
如果需要查看用户、ip和时间,需要配置linux的变量。
编辑
vim /etc/profile
后面添加变量:
export HISTTIMEFORMAT="%F %T `who am i` "
然后使之生效:
source /etc/profile
[root@localhost etc]# history 20
1022 2020-02-02 17:03:16 root pts/1 2020-02-02 13:31 (192.168.190.14) echo 'world' 1>>echo.log1023 2020-02-02 17:03:20 root pts/1 2020-02-02 13:31 (192.168.190.14) cat echo.log1024 2020-02-02 17:03:28 root pts/1 2020-02-02 13:31 (192.168.190.14) echo 'world' 1>echo.log1025 2020-02-02 17:03:31 root pts/1 2020-02-02 13:31 (192.168.190.14) cat echo.log1026 2020-02-02 17:09:05 root pts/1 2020-02-02 13:31 (192.168.190.14) ll1027 2020-02-02 17:09:11 root pts/1 2020-02-02 13:31 (192.168.190.14) rm echo.log1028 2020-02-02 17:12:58 root pts/1 2020-02-02 13:31 (192.168.190.14) last1029 2020-02-02 17:14:15 root pts/1 2020-02-02 13:31 (192.168.190.14) history1030 2020-02-02 17:47:12 root pts/1 2020-02-02 13:31 (192.168.190.14) who am i1031 2020-02-02 17:53:15 root pts/1 2020-02-02 13:31 (192.168.190.14) clear1032 2020-02-02 17:53:21 root pts/1 2020-02-02 13:31 (192.168.190.14) history1033* 2020-02-02 17:53:29 root pts/1 2020-02-02 13:31 (192.168.190.14)1034 2020-02-02 17:53:40 root pts/1 2020-02-02 13:31 (192.168.190.14) history 20
1035 2020-02-02 17:55:12 root pts/1 2020-02-02 13:31 (192.168.190.14) last1036 2020-02-02 17:58:23 root pts/1 2020-02-02 13:31 (192.168.190.14) cd /etc1037 2020-02-02 17:58:25 root pts/1 2020-02-02 13:31 (192.168.190.14) ll1038 2020-02-02 17:58:33 root pts/1 2020-02-02 13:31 (192.168.190.14) vim profile1039 2020-02-02 18:01:54 root pts/1 2020-02-02 13:31 (192.168.190.14) source /etc/profile1040 2020-02-02 18:02:03 root pts/1 2020-02-02 13:31 (192.168.190.14) histoty 20
1041 2020-02-02 18:02:10 root pts/1 2020-02-02 13:31 (192.168.190.14) history 20
可以看到多出了,操作时间,用户,以及操作的ip。
who am i 比较容易理解,就是输出登入的用户名,登入时间,以及ip啥的。
那%F %T啥的,其实就是一种格式。这种格式是strftime函数。可以搜索了解下strftime。