在 Debian 系统中,“历史日志”通常指 systemd journal 日志、/var/log 下的传统日志文件,以及 shell 历史命令。下面分情况说明如何“清空”。
sudo journalctl --vacuum-time=1s
或彻底删除:
sudo rm -rf /var/log/journal/*
sudo systemctl restart systemd-journald
sudo journalctl --vacuum-time=7d
sudo journalctl --vacuum-size=100M
sudo truncate -s 0 /var/log/syslog
sudo truncate -s 0 /var/log/auth.log
sudo truncate -s 0 /var/log/kern.log
⚠️ 有风险,仅建议测试环境
sudo find /var/log -type f -exec truncate -s 0 {} \;
Debian 默认已启用 logrotate,可强制轮转并清空:
sudo logrotate -f /etc/logrotate.conf
history -c
history -w
或:
> ~/.bash_history
sudo find /home -name ".bash_history" -exec truncate -s 0 {} \;
sudo truncate -s 0 /root/.bash_history
sudo systemctl stop systemd-journald
sudo systemctl disable systemd-journald
journalctl --vacuum-* 或 logrotaterm -rf /var/log,可能导致服务异常如果你有具体想清空的日志类型(如 nginx、docker、apt),可以告诉我。