vi /etc/profile
#history
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`if [ -z $USER_IP ]
then
USER_IP=`hostname`
fi
export HISTTIMEFORMAT="[%Y.%m.%d %H:%M:%S] [${USER_IP}-${LOGNAME}]"
source /etc/profile
history
效果
999 [2016.08.18 09:48:06] [10.1.193.116-root]ll
1000 [2016.08.18 09:48:19] [10.1.193.116-root]find / -name .bashrc
1001 [2016.08.18 10:22:36] [10.1.193.116-root]more /etc/profile
1002 [2016.08.18 10:22:45] [10.1.193.116-root] vi /etc/profile
1003 [2016.08.18 10:22:55] [10.1.193.116-root]more /etc/profile
1004 [2016.08.18 10:23:00] [10.1.193.116-root] vi /etc/profile
1005 [2016.08.18 10:27:16] [10.1.193.116-root] vi -r /etc/profile
1006 [2016.08.18 10:29:12] [10.1.193.116-root]source /etc/profile
1007 [2016.08.18 10:29:20] [10.1.193.116-root]more /etc/profile
1008 [2016.08.18 10:29:24] [10.1.193.116-root] history
1009 [2016.08.18 10:29:50] [10.1.193.116-root]more /etc/profile
1010 [2016.08.18 10:44:30] [10.1.193.116-root]vi /etc/profile
1011 [2016.08.18 10:46:35] [10.1.193.116-root]ll
1012 [2016.08.18 10:47:04] [10.1.193.116-root]history
1013 [2016.08.18 10:47:13] [10.1.193.116-root]source /etc/profile
1014 [2016.08.18 10:47:16] [10.1.193.116-root]history
1015 [2016.08.18 10:47:46] [10.1.193.116-root]ll
1016 [2016.08.18 10:47:49] [10.1.193.116-root]soft
1017 [2016.08.18 10:47:49] [10.1.193.116-root]ll
1018 [2016.08.18 10:47:52] [10.1.193.116-root]cd soft
1019 [2016.08.18 10:47:53] [10.1.193.116-root]ll
1020 [2016.08.18 10:48:27] [10.1.193.116-root]history
1021 [2016.08.18 10:57:47] [10.1.193.116-root]more /etc/profile
1022 [2016.08.18 10:57:55] [10.1.193.116-root] #history
1023 [2016.08.18 10:57:55] [10.1.193.116-root]USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
1024 [2016.08.18 10:57:55] [10.1.193.116-root]if [ -z $USER_IP ]; then USER_IP=`hostname`; fi
1025 [2016.08.18 11:00:25] [10.1.193.116-root]export HISTTIMEFORMAT="[%Y.%m.%d %H:%M:%S] [${USER_IP}-${LOGNAME}]"
1026 [2016.08.18 11:00:27] [10.1.193.116-root]history
本文介绍了一种在Linux系统中自定义bash历史命令记录格式的方法,通过修改/etc/profile文件实现带有时间戳、IP地址和用户名的历史命令记录,提高了命令历史的可读性和追踪性。
1157

被折叠的 条评论
为什么被折叠?



