Skip to main content

清除日志

sudo journalctl --rotate
sudo journalctl --vacuum-time=1s

find /var/log -type f -name "*.log" -exec truncate -s 0 {} \;

rm -f /var/log/*.[0-9]
rm -f /var/log/*.[0-9].*
rm -f /var/log/*.gz
rm -f /var/log/*.xz

truncate -s 0 /var/log/syslog
truncate -s 0 /var/log/auth.log
truncate -s 0 /var/log/kern.log
truncate -s 0 /var/log/dmesg
truncate -s 0 /var/log/dpkg.log
truncate -s 0 /var/log/alternatives.log
truncate -s 0 /var/log/btmp
truncate -s 0 /var/log/utmp
truncate -s 0 /var/log/wtmp
truncate -s 0 /var/log/lastlog

echo ""
> /var/log/wtmp
> /var/log/btmp
> /var/log/lastlog

find /var/log/apt -type f -exec truncate -s 0 {} \;
sudo rm -f /var/log/apt/*.[0-9]
sudo rm -f /var/log/apt/*.[0-9].*
sudo rm -f /var/log/apt/*.gz
sudo rm -f /var/log/apt/*.xz

journalctl --vacuum-time=1s

for DIR in $(find /var/log -maxdepth 1 -type d | grep -v "^/var/log$" | grep -v "^/var/log/journal$"); do
find $DIR -type f -name "*.log" -exec truncate -s 0 {} \; 2>/dev/null
rm -f $DIR/*.[0-9] 2>/dev/null
rm -f $DIR/*.[0-9].* 2>/dev/null
rm -f $DIR/*.gz 2>/dev/null
rm -f $DIR/*.xz 2>/dev/null
done

systemctl restart rsyslog

> ~/.bash_history
history -c

find /home -name ".bash_history" -exec truncate -s 0 {} \; 2>/dev/null
find /root -name ".bash_history" -exec truncate -s 0 {} \; 2>/dev/null
find /home -name ".*_history" -exec truncate -s 0 {} \; 2>/dev/null
find /root -name ".*_history" -exec truncate -s 0 {} \; 2>/dev/null

history -c
history -w
clear