- 工信部备案号 滇ICP备05000110号-1
- 滇公网安备53011102001527号
- 增值电信业务经营许可证 B1.B2-20181647、滇B1.B2-20190004
- 云南互联网协会理事单位
- 安全联盟认证网站身份V标记
- 域名注册服务机构许可:滇D3-20230001
- 代理域名注册服务机构:新网数码
- CN域名投诉举报处理平台:电话:010-58813000、邮箱:service@cnnic.cn
欢迎来到8455线路检测中心技术小课堂,每天分享一个技术小知识。在Linux服务器运维中,磁盘空间占满是高频故障——它会导致服务崩溃、日志无法写入、系统卡死,很多新手面对满盘时手足无措。比如分不清哪些文件能删、不敢动系统目录、不知道大文件藏在哪,今天我们就聚焦 Linux磁盘空间清理,用几个命令快速搞定满盘问题,全是干货,新手直接套用。
关键看Use%列,超过80%需警惕,100%则紧急处理。-h参数让大小单位人性化(GB/MB)。
df -h
列出根目录下所有目录的大小,sort -hr按从大到小排序,快速定位占用大户(如/var//home)。
du -sh /* | sort -hr
搜索/var目录下大于100M的文件,-ls显示文件详情(大小、路径)。可调整+100M为+1G找超大文件。
find /var -type f -size +100M -ls
日志是磁盘占用重灾区,/var/log/下的旧日志可放心删:
# 清空单个日志(不删除文件,避免服务报错) > /var/log/messages # 删除7天前的旧日志 find /var/log -name "*.log" -mtime +7 -delete
# Ubuntu/Debian sudo apt clean # CentOS/RHEL sudo yum clean all
# 查找并删除当前目录下的.tar.gz/.zip包 find . -name "*.tar.gz" -delete find . -name "*.zip" -delete
有些文件删除后空间没释放,是因为进程还在占用:
# 查找这类文件 lsof | grep deleted # 重启对应进程释放空间(比如进程PID为1234) kill -9 1234
绝对不能删的目录:/bin//sbin//lib//boot,删了系统直接崩。
清空日志优先用> 文件名,而非rm,避免服务找不到日志文件报错。
不确定的文件先备份,或者用mv移到临时目录,观察1天无异常再删除。
掌握Linux磁盘清理的核心命令,能快速解决满盘故障,从df -h查看使用率,到du定位大目录,再到针对性清理日志和缓存,每一步都简单高效。新手只需牢记“先查后删、谨慎操作”的原则,就能避免踩坑。
8455线路检测中心官网上有更详细的Linux磁盘管理手册,包含磁盘扩容、分区优化等进阶内容,大家可自行查阅。更多技术问题,可直接咨询8455线路检测中心技术支持;我们整理的“Linux运维必备工具包”中,也包含了磁盘监控脚本、自动清理工具,需要的朋友随时联系获取。
/var/log/messages\\\\\\\\n# 删除7天前的旧日志\\\\\\\\nfind /var/log -name \\\\\\\\"*.log\\\\\\\\" -mtime +7 -delete"},"attribs":{"0":"*0|3+1j*0+19"}},"apool":{"numToAttrib":{"0":["author","974610658236027"]},"nextNum":1}},"align":"","language":"bash","wrap":false,"caption":{"text":{"apool":{"nextNum":0,"numToAttrib":{}},"initialAttributedTexts":{"attribs":{"0":"|1+1"},"text":{"0":"\\\\\\\\n"}}}}}},"XOAEfNO4YdBM5wcYcqNcpSZ4nmh":{"id":"XOAEfNO4YdBM5wcYcqNcpSZ4nmh","snapshot":{"type":"heading3","parent_id":"N21vfo4qpdFGKnc0jcEcQq9wnRf","comments":[],"revisions":[],"locked":false,"hidden":false,"author":"974610658236027","children":[],"text":{"initialAttributedTexts":{"text":{"0":"2. 清理软件缓存"},"attribs":{"0":"*0+9"}},"apool":{"numToAttrib":{"0":["author","974610658236027"]},"nextNum":1}},"align":""}},"Qh0of7Ky9dPZfTcw6xHcTMVSnDf":{"id":"Qh0of7Ky9dPZfTcw6xHcTMVSnDf","snapshot":{"type":"code","parent_id":"N21vfo4qpdFGKnc0jcEcQq9wnRf","comments":[],"revisions":[],"locked":false,"hidden":false,"author":"974610658236027","children":[],"text":{"initialAttributedTexts":{"text":{"0":"# Ubuntu/Debian\\\\\\\\nsudo apt clean\\\\\\\\n# CentOS/RHEL\\\\\\\\nsudo yum clean all"},"attribs":{"0":"*0|3+19*0+i"}},"apool":{"numToAttrib":{"0":["author","974610658236027"]},"nextNum":1}},"align":"","language":"bash","wrap":false,"caption":{"text":{"apool":{"nextNum":0,"numToAttrib":{}},"initialAttributedTexts":{"attribs":{"0":"|1+1"},"text":{"0":"\\\\\\\\n"}}}}}},"JerTfTR2edvq5scaHoYcr85knpg":{"id":"JerTfTR2edvq5scaHoYcr85knpg","snapshot":{"type":"heading3","parent_id":"N21vfo4qpdFGKnc0jcEcQq9wnRf","comments":[],"revisions":[],"locked":false,"hidden":false,"author":"974610658236027","children":[],"text":{"initialAttributedTexts":{"text":{"0":"3. 删除无用压缩包/安装包"},"attribs":{"0":"*0+e"}},"apool":{"numToAttrib":{"0":["author","974610658236027"]},"nextNum":1}},"align":""}},"LQQHfOD5cdgynLcFbEhc6JvJnUf":{"id":"LQQHfOD5cdgynLcFbEhc6JvJnUf","snapshot":{"type":"code","parent_id":"N21vfo4qpdFGKnc0jcEcQq9wnRf","comments":[],"revisions":[],"locked":false,"hidden":false,"author":"974610658236027","children":[],"text":{"initialAttributedTexts":{"text":{"0":"# 查找并删除当前目录下的.tar.gz/.zip包\\\\\\\\nfind . -name \\\\\\\\"*.tar.gz\\\\\\\\" -delete\\\\\\\\nfind . -name \\\\\\\\"*.zip\\\\\\\\" -delete"},"attribs":{"0":"*0|2+1n*0+s"}},"apool":{"numToAttrib":{"0":["author","974610658236027"]},"nextNum":1}},"align":"","language":"bash","wrap":false,"caption":{"text":{"apool":{"nextNum":0,"numToAttrib":{}},"initialAttributedTexts":{"attribs":{"0":"|1+1"},"text":{"0":"\\\\\\\\n"}}}}}},"HfoIfvy6Nd71xpcgOeQcVhHOnGb":{"id":"HfoIfvy6Nd71xpcgOeQcVhHOnGb","snapshot":{"type":"heading3","parent_id":"N21vfo4qpdFGKnc0jcEcQq9wnRf","comments":[],"revisions":[],"locked":false,"hidden":false,"author":"974610658236027","children":[],"text":{"initialAttributedTexts":{"text":{"0":"4. 清理僵尸文件(已删除但仍被进程占用)"},"attribs":{"0":"*0+l"}},"apool":{"numToAttrib":{"0":["author","974610658236027"]},"nextNum":1}},"align":""}},"UY7ifn3SLdd1Brcd2o7cFYZ5n6f":{"id":"UY7ifn3SLdd1Brcd2o7cFYZ5n6f","snapshot":{"type":"text","parent_id":"N21vfo4qpdFGKnc0jcEcQq9wnRf","comments":[],"revisions":[],"locked":false,"hidden":false,"author":"974610658236027","children":[],"text":{"initialAttributedTexts":{"text":{"0":"有些文件删除后空间没释放,是因为进程还在占用:"},"attribs":{"0":"*0+n"}},"apool":{"numToAttrib":{"0":["author","974610658236027"]},"nextNum":1}},"align":""}},"TFUefATDZdg1QYchARTcZEblnbh":{"id":"TFUefATDZdg1QYchARTcZEblnbh","snapshot":{"type":"code","parent_id":"N21vfo4qpdFGKnc0jcEcQq9wnRf","comments":[],"revisions":[],"locked":false,"hidden":false,"author":"974610658236027","children":[],"text":{"initialAttributedTexts":{"text":{"0":"# 查找这类文件\\\\\\\\nlsof | grep deleted\\\\\\\\n# 重启对应进程释放空间(比如进程PID为1234)\\\\\\\\nkill -9 1234"},"attribs":{"0":"*0|3+1k*0+c"}},"apool":{"numToAttrib":{"0":["author","974610658236027"]},"nextNum":1}},"align":"","language":"bash","wrap":false,"caption":{"text":{"apool":{"nextNum":0,"numToAttrib":{}},"initialAttributedTexts":{"attribs":{"0":"|1+1"},"text":{"0":"\\\\\\\\n"}}}}}},"RiWcfl3j5d7NVFcP1QrcyA6inbf":{"id":"RiWcfl3j5d7NVFcP1QrcyA6inbf","snapshot":{"type":"heading2","parent_id":"N21vfo4qpdFGKnc0jcEcQq9wnRf","comments":[],"revisions":[],"locked":false,"hidden":false,"author":"974610658236027","children":[],"text":{"initialAttributedTexts":{"text":{"0":"三、避坑提醒"},"attribs":{"0":"*0+6"}},"apool":{"numToAttrib":{"0":["author","974610658236027"]},"nextNum":1}},"align":""}},"DgCgfMWfcdnmYZceAybcpvImnLb":{"id":"DgCgfMWfcdnmYZceAybcpvImnLb","snapshot":{"type":"ordered","parent_id":"N21vfo4qpdFGKnc0jcEcQq9wnRf","comments":[],"revisions":[],"locked":false,"hidden":false,"author":"974610658236027","children":[],"text":{"initialAttributedTexts":{"text":{"0":"绝对不能删的目录:/bin//sbin//lib//boot,删了系统直接崩。"},"attribs":{"0":"*0+9*0*1+4*0+1*0*1+5*0+1*0*1+4*0+1*0*1+5*0+9"}},"apool":{"numToAttrib":{"0":["author","974610658236027"],"1":["inlineCode","true"]},"nextNum":2}},"align":"","seq":"1"}},"FrI9fJb0Jdih4NcDztVcwnS1nMh":{"id":"FrI9fJb0Jdih4NcDztVcwnS1nMh","snapshot":{"type":"ordered","parent_id":"N21vfo4qpdFGKnc0jcEcQq9wnRf","comments":[],"revisions":[],"locked":false,"hidden":false,"author":"974610658236027","children":[],"text":{"initialAttributedTexts":{"text":{"0":"清空日志优先用> 文件名,而非rm,避免服务找不到日志文件报错。"},"attribs":{"0":"*0+7*0*1+5*0+3*0*1+2*0+f"}},"apool":{"numToAttrib":{"0":["author","974610658236027"],"1":["inlineCode","true"]},"nextNum":2}},"align":""}},"ZwjlfmozUd9N1CcLWQ6cNjWSnBf":{"id":"ZwjlfmozUd9N1CcLWQ6cNjWSnBf","snapshot":{"type":"ordered","parent_id":"N21vfo4qpdFGKnc0jcEcQq9wnRf","comments":[],"revisions":[],"locked":false,"hidden":false,"author":"974610658236027","children":[],"text":{"initialAttributedTexts":{"text":{"0":"不确定的文件先备份,或者用mv移到临时目录,观察1天无异常再删除。"},"attribs":{"0":"*0+d*0*1+2*0+i"}},"apool":{"numToAttrib":{"0":["author","974610658236027"],"1":["inlineCode","true"]},"nextNum":2}},"align":""}},"OnnzfDrZVdg25lcIGQocVXMjnte":{"id":"OnnzfDrZVdg25lcIGQocVXMjnte","snapshot":{"type":"heading2","parent_id":"N21vfo4qpdFGKnc0jcEcQq9wnRf","comments":[],"revisions":[],"locked":false,"hidden":false,"author":"974610658236027","children":[],"text":{"initialAttributedTexts":{"text":{"0":"四、总结"},"attribs":{"0":"*0+4"}},"apool":{"numToAttrib":{"0":["author","974610658236027"]},"nextNum":1}},"align":""}},"KC9YfS9iWdHv2Gcx2pEcLrlGnVf":{"id":"KC9YfS9iWdHv2Gcx2pEcLrlGnVf","snapshot":{"type":"text","parent_id":"N21vfo4qpdFGKnc0jcEcQq9wnRf","comments":[],"revisions":[],"locked":false,"hidden":false,"author":"974610658236027","children":[],"text":{"initialAttributedTexts":{"text":{"0":"掌握Linux磁盘清理的核心命令,能快速解决满盘故障,从df -h查看使用率,到du定位大目录,再到针对性清理日志和缓存,每一步都简单高效。新手只需牢记“先查后删、谨慎操作”的原则,就能避免踩坑。"},"attribs":{"0":"*0+s*0*1+5*0+7*0*1+2*0+1k"}},"apool":{"numToAttrib":{"0":["author","974610658236027"],"1":["inlineCode","true"]},"nextNum":2}},"align":""}},"OdQJfKMfWdtGnZc2AoxcYPiYnTh":{"id":"OdQJfKMfWdtGnZc2AoxcYPiYnTh","snapshot":{"type":"text","parent_id":"N21vfo4qpdFGKnc0jcEcQq9wnRf","comments":[],"revisions":[],"locked":false,"hidden":false,"author":"974610658236027","children":[],"text":{"initialAttributedTexts":{"text":{"0":"8455线路检测中心官网上有更详细的Linux磁盘管理手册,包含磁盘扩容、分区优化等进阶内容,大家可自行查阅。更多技术问题,可直接咨询8455线路检测中心技术支持;我们整理的“Linux运维必备工具包”中,也包含了磁盘监控脚本、自动清理工具,需要的朋友随时联系获取。"},"attribs":{"0":"*0+3b"}},"apool":{"numToAttrib":{"0":["author","974610658236027"]},"nextNum":1}},"align":""}}},"payloadMap":{"E1pafgr8Xd8ip0cvoFlcCjSvnLE":{"level":1},"BFFnf1X09dmdeWcqkMwcLECInPe":{"level":1},"Nwk3fAP7HdtLU7cYk73c9dZ6nmh":{"level":1},"PSxDfbmJxdKGEhcCVjEc384tnPc":{"level":1},"ChdHfWHlBdBNjicYudxcM7oWn1c":{"level":1},"UY7ifn3SLdd1Brcd2o7cFYZ5n6f":{"level":1},"KC9YfS9iWdHv2Gcx2pEcLrlGnVf":{"level":1},"OdQJfKMfWdtGnZc2AoxcYPiYnTh":{"level":1}},"extra":{"channel":"saas","pasteRandomId":"fbb6e09f-13c1-4428-a3a4-a06e8d4c2b19","mention_page_title":{},"external_mention_url":{}},"isKeepQuoteContainer":false,"selection":[{"id":279,"type":"block","recordId":"N21vfo4qpdFGKnc0jcEcQq9wnRf"},{"id":280,"type":"block","recordId":"E1pafgr8Xd8ip0cvoFlcCjSvnLE"},{"id":281,"type":"block","recordId":"BHJnfpykBdCvTgcW96NclZNWnSM"},{"id":282,"type":"block","recordId":"DEDNfGSDEdwyuwclNpFcLQTEnZe"},{"id":283,"type":"block","recordId":"BFFnf1X09dmdeWcqkMwcLECInPe"},{"id":284,"type":"block","recordId":"ZD7rfb1jLdotztcA656cRQPrnpe"},{"id":285,"type":"block","recordId":"LJaMfKiTRdx4qYcaH30ceq0ynfd"},{"id":286,"type":"block","recordId":"Nwk3fAP7HdtLU7cYk73c9dZ6nmh"},{"id":287,"type":"block","recordId":"HOInfAFIJdi7oKc6cT0cnjccnHh"},{"id":288,"type":"block","recordId":"E5yLffh5MdOEfWcwj8AcV6lenOg"},{"id":289,"type":"block","recordId":"PSxDfbmJxdKGEhcCVjEc384tnPc"},{"id":290,"type":"block","recordId":"TrljfkvEZdvphBcUJ83cBg6pn4f"},{"id":291,"type":"block","recordId":"Vb8lf2iGCdTBQZcFD3HcW4JQn4d"},{"id":292,"type":"block","recordId":"BIcBf1OAKdyiNwcizpOcmEhYnVu"},{"id":293,"type":"block","recordId":"ChdHfWHlBdBNjicYudxcM7oWn1c"},{"id":294,"type":"block","recordId":"UiwwfxZusdS0FjcE7VccbvA1nWf"},{"id":295,"type":"block","recordId":"XOAEfNO4YdBM5wcYcqNcpSZ4nmh"},{"id":296,"type":"block","recordId":"Qh0of7Ky9dPZfTcw6xHcTMVSnDf"},{"id":297,"type":"block","recordId":"JerTfTR2edvq5scaHoYcr85knpg"},{"id":298,"type":"block","recordId":"LQQHfOD5cdgynLcFbEhc6JvJnUf"},{"id":299,"type":"block","recordId":"HfoIfvy6Nd71xpcgOeQcVhHOnGb"},{"id":300,"type":"block","recordId":"UY7ifn3SLdd1Brcd2o7cFYZ5n6f"},{"id":301,"type":"block","recordId":"TFUefATDZdg1QYchARTcZEblnbh"},{"id":302,"type":"block","recordId":"RiWcfl3j5d7NVFcP1QrcyA6inbf"},{"id":303,"type":"block","recordId":"DgCgfMWfcdnmYZceAybcpvImnLb"},{"id":304,"type":"block","recordId":"FrI9fJb0Jdih4NcDztVcwnS1nMh"},{"id":305,"type":"block","recordId":"ZwjlfmozUd9N1CcLWQ6cNjWSnBf"},{"id":306,"type":"block","recordId":"OnnzfDrZVdg25lcIGQocVXMjnte"},{"id":307,"type":"block","recordId":"KC9YfS9iWdHv2Gcx2pEcLrlGnVf"},{"id":308,"type":"block","recordId":"OdQJfKMfWdtGnZc2AoxcYPiYnTh"}],"pasteFlag":"d4207699-8326-4aa0-8270-7957d3a3ad21"}" data-lark-record-format="docx/record" class="lark-record-clipboard">
售前咨询
售后咨询
备案咨询
二维码

TOP