在 CentOS 系统中,“清理历史记录”通常指 清理命令历史记录(history),也可能包括 日志、缓存、登录记录 等。下面按常见场景给你一个完整说明。
history
history -c
⚠️ 注意:
这只是清空内存中的历史,不会立即删除~/.bash_history文件。
rm -f ~/.bash_history
unset HISTFILE
或者临时关闭历史记录:
set +o history
history -c
history -w
或一条命令:
cat /dev/null > ~/.bash_history && history -c
for user in $(ls /home); do
> /home/$user/.bash_history
done
> /root/.bash_history
journalctl --vacuum-time=1d
或保留 100MB:
journalctl --vacuum-size=100M
> /var/log/messages
> /var/log/secure
> /var/log/audit/audit.log
⚠️ 不建议直接删除日志文件,否则服务可能异常。
> /var/log/wtmp # 登录记录
> /var/log/btmp # 错误登录
> /var/log/lastlog # 最后登录
查看登录历史:
last
lastb
yum clean all
或(CentOS 8+):
dnf clean all
编辑 ~/.bashrc:
export HISTSIZE=0
export HISTFILESIZE=0
或完全禁用:
unset HISTFILE
生效:
source ~/.bashrc
shred -u ~/.bash_history
history -c
cat /dev/null > ~/.bash_history
如果你是想:
可以告诉我具体使用场景,我可以给你更精准的方案。