作为IT工程师,我整理了一套全面的Linux系统清理方法,帮助您提升系统性能并释放宝贵资源。
# 查找大于100MB的文件
sudo find / -type f -size +100M -exec ls -lh {} \;
# 按大小排序显示目录
sudo du -h --max-depth=1 / | sort -h
# Debian/Ubuntu
sudo apt-get clean
sudo apt-get autoremove
# RHEL/CentOS
sudo yum clean all
sudo dnf clean all
# 查看日志文件大小
sudo du -sh /var/log/
# 清空特定日志文件
sudo truncate -s 0 /var/log/syslog
free -h
top
htop
# 释放pagecache, dentries和inodes
sudo sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
ps aux --sort=-%mem | head -10 # 按内存排序
ps aux --sort=-%cpu | head -10 # 按CPU排序
kill -9 [PID] # 强制终止进程
pkill [进程名] # 按名称终止
设置cron作业定期清理:
# 编辑crontab
crontab -e
# 示例:每周日凌晨3点清理
0 3 * * 0 /usr/bin/apt-get clean
0 3 * * 0 /usr/bin/apt-get autoremove -y
通过定期执行这些清理操作,您的Linux系统将保持高效运行状态,性能得到显著提升。