history命令记录操作时间、操作用户、操作IP
优化历史命令 history 显示格式
]# cat /etc/profile ... export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S " USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'` export HISTTIMEFORMAT="[%F %T][`whoami`][${USER_IP}] "
使配置生效
source /etc/profile
查看效果
]# history 1 [2021-12-23 03:55:27][root][192.168.64.1] exit 2 [2021-12-23 03:55:27][root][192.168.64.1] hostnamectl set-hostname jenkins-3 3 [2021-12-23 03:55:27][root][192.168.64.1] ll 4 [2021-12-23 03:55:27][root][192.168.64.1] tar -xvf jdk-8u212-linux-x64.tar.gz 5 [2021-12-23 03:55:27][root][192.168.64.1] rm -rf jdk-8u212-linux-x64.tar.gz 6 [2021-12-23 03:55:27][root][192.168.64.1] mkdir apps 7 [2021-12-23 03:55:27][root][192.168.64.1] exit 8 [2021-12-23 03:56:08][root][192.168.64.1] mkdir apps 9 [2021-12-23 03:56:14][root][192.168.64.1] ll 10 [2021-12-23 03:56:22][root][192.168.64.1] mv jdk1.8.0_212/ apps/ 11 [2021-12-23 03:56:24][root][192.168.64.1] cd apps/ 12 [2021-12-23 03:56:28][root][192.168.64.1] mkdir jdk 13 [2021-12-23 03:56:40][root][192.168.64.1] ln -sv jdk1.8.0_212/ jdk 14 [2021-12-23 03:56:43][root][192.168.64.1] ll jdk 15 [2021-12-23 03:57:00][root][192.168.64.1] source /etc/profile && java -version 16 [2021-12-23 04:01:52][root][192.168.64.1] cd 17 [2021-12-23 04:01:53][root][192.168.64.1] tar -xvf apache-tomcat-8.5.61.tar.gz -C apps/ 18 [2021-12-23 04:02:05][root][192.168.64.1] rm -rf apache-tomcat-8.5.61.tar.gz 19 [2021-12-23 04:03:13][root][192.168.64.1] cd apps/ 20 [2021-12-23 04:03:14][root][192.168.64.1] ll 21 [2021-12-23 04:03:17][root][192.168.64.1] mkdir tomcat 22 [2021-12-23 04:03:25][root][192.168.64.1] ln -sv apache-tomcat-8.5.61/ tomcat/ 23 [2021-12-23 04:03:27][root][192.168.64.1] ll 24 [2021-12-23 04:08:22][root][192.168.64.1] java -version 25 [2021-12-23 04:08:40][root][192.168.64.1] history 26 [2021-12-23 04:08:53][root][192.168.64.1] vim /etc/profile 27 [2021-12-23 04:11:14][root][192.168.64.1] source /etc/profile 28 [2021-12-23 04:11:19][root][192.168.64.1] history 29 [2021-12-23 04:11:25][root][192.168.64.1] source /etc/profile 30 [2021-12-23 04:11:27][root][192.168.64.1] vim /etc/profile 31 [2021-12-23 04:12:12][root][192.168.64.1] echo %T 32 [2021-12-23 04:12:22][root][192.168.64.1] echo $%T 33 [2021-12-23 04:12:26][root][192.168.64.1] echo $T 34 [2021-12-23 04:12:33][root][192.168.64.1] source /etc/profile 35 [2021-12-23 04:12:36][root][192.168.64.1] history 36 [2021-12-23 04:12:42][root][192.168.64.1] vim /etc/profile 37 [2021-12-23 04:13:15][root][192.168.64.1] source /etc/profile 38 [2021-12-23 04:13:16][root][192.168.64.1] history 39 [2021-12-23 04:13:21][root][192.168.64.1] vim /etc/profile 40 [2021-12-23 04:19:39][root][192.168.64.1] source /etc/profile 41 [2021-12-23 04:19:42][root][192.168.64.1] history
越学越感到自己的无知