在Linux系统中,有许多实用的清理命令可以帮助你释放磁盘空间、删除不必要的文件和优化系统性能。以下是一些常用的Linux清理命令及其实用技巧:
df -hgrep过滤特定分区或文件系统。df -h | grep '/dev/sda1'
du -sh *sort按大小排序。du -sh * | sort -h
rm-r递归删除目录。-f强制删除,不提示确认。rm -rf /path/to/directory
findfind /path/to/search -type f -size +100M -exec rm {} \;
ncdu-r递归扫描目录,使用-q静默模式。ncdu -r /path/to/directory
bleachbitapt-get cleansudo apt-get clean
yum clean allsudo yum clean all
systemd-cleanup--time=30d删除30天前的日志。sudo systemd-cleanup --time=30d
tmpwatchsudo tmpwatch 24h /tmp/*
logrotate/etc/logrotate.conf或相关配置文件。fstrimsudo fstrim /
rm -rf时要格外小心,因为它会无提示地删除所有内容。通过合理使用这些命令和技巧,你可以有效地管理和优化Linux系统的存储空间。