Skip to content

Release and recycle disk space on Linux

未在使用的文件删除

rm -f filename

如果该文件句柄正在被打开/写入,直接rm会导致磁盘空间并没有释放,可以考虑通过重定向方式释放文件空间。

正在使用的文件清空

cat /dev/null > filename
: > filename
> filename
echo "" > filename
echo > filename

Disclaimer
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback me#imzye.me, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Try my iOS App