在 Linux 系统中,“历史日志”通常指 系统日志、应用日志、命令历史 等。下面按常见场景给你一套安全、实用的清理方法。
journalctl(systemd 系统)适用于 CentOS 7+/Ubuntu 16.04+
# 查看日志占用
journalctl --disk-usage
# 只保留最近 7 天
journalctl --vacuum-time=7d
# 只保留 500MB
journalctl --vacuum-size=500M
✅ 推荐方式,安全不破坏系统
/var/log 下的日志文件常见日志:
/var/log/messages/var/log/secure/var/log/syslog/var/log/nginx//var/log/httpd/> /var/log/messages
> /var/log/secure
logrotate -f /etc/logrotate.conf
history -c
> ~/.bash_history
rm -f /home/*/.bash_history
> /var/log/audit/audit.log
> /var/log/wtmp
> /var/log/btmp
查看登录记录:
last
lastb
find /var/log -type f -mtime +30 -exec rm -f {} \;
加入 crontab:
0 2 * * * find /var/log -type f -mtime +30 -delete
rm -rf /var/logjournalctl / logrotate你是 服务器运维 / 安全清理 / 释放磁盘空间 哪种需求?