linux执行脚本查找ip,linux 查看ip、用户、时间对应执行的命令

这个需要使用到history命令。可以加数字,返回最近执行的几条命令。如果不加数字会返回所有的历史命令。

[[email protected] ~]# 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

[[email protected] 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。

原文:https://www.cnblogs.com/chenmz1995/p/12253058.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值