Linux自动备份history记录

编辑[环境变量]配置文件

# 打开文件
vi /etc/profile


# 插入下边代码
export PROMPT_COMMAND='{ msg=$(history 1 | { read x y; echo $y; });echo  "[euid=$(whoami)]":$(who am i):[`pwd`]#"$msg" >>/tmp/history_cmd.log; }'
创建log文件
touch /tmp/history_cmd.log  # 创建log文件
chmod 777 /tmp/history_cmd.log # 设置文件权限
使环境变量生效
source /etc/profile
查看log文件
cat /tmp/history_cmd.log

猜你喜欢

转载自blog.csdn.net/lixu1119545729/article/details/131763666