优化history命令输出信息
优化方法:
在/etc/profile尾部追加如下内容
HISTFILESIZE=4000 #默认保存命令是1000条,这里修改为4000条
HISTSIZE=4000
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'` #取得登录客户端的IP
if [ -z $USER_IP ]
then
USER_IP=`hostname`
fi
HISTTIMEFORMAT="%F %T $USER_IP:`whoami` " #设置新的显示history的格式
export HISTTIMEFORMAT
执行source /etc/profile使其生效
效果示例:
2553 2022-06-03 23:03:08 114.45.18.236:root vim /etc/sysctl.conf
2554 2022-06-03 23:03:10 114.45.18.236:root vim /etc/sysctl.conf
2555 2022-06-03 23:03:17 114.45.18.236:root lsmod |grep bbr
2556 2022-06-03 23:03:19 114.45.18.236:root lsmod |grep fq
2557 2022-06-03 23:03:45 114.45.18.236:root ls
2558 2022-06-03 23:03:46 114.45.18.236:root ll
2559 2022-06-03 23:03:49 114.45.18.236:root cd
2560 2022-06-03 23:03:49 114.45.18.236:root ls
2561 2022-06-03 23:03:53 114.45.18.236:root screen -ls
2562 2022-06-03 23:03:56 114.45.18.236:root screen -r oracle
2563 2022-06-03 23:04:02 114.45.18.236:root screen -S oracle1
2564 2022-06-03 23:04:39 114.45.18.236:root crontab -l