文件清理后,磁盘没及时同步。

事件: 发现 df 不足, 检查是某个日志太大, 于是删除日志, 再次 df -h 检查 磁盘。 发现没及时同步。

  1. root@远盛09-GPU号(70-85-C2-88-27-97):/# df -h
  2. 文件系统 容量 已用 可用 已用% 挂载点
  3. udev 3.9G 0 3.9G 0% /dev
  4. tmpfs 790M 70M 720M 9% /run
  5. /dev/sda1 32G 20G 11G 64% /
  6. tmpfs 3.9G 252K 3.9G 1% /dev/shm
  7. tmpfs 5.0M 4.0K 5.0M 1% /run/lock
  8. tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
  9. /dev/sda2 174G 46G 120G 28% /data
  10. tmpfs 1000M 370M 631M 37% /data/tmp
  11. tmpfs 790M 4.0K 790M 1% /run/user/112
  12. tmpfs 790M 0 790M 0% /run/user/1000
  13. root@远盛09-GPU号(70-85-C2-88-27-97):/# du -sh /var/log/obsolete-flaw-checker-log/* |grep G
  14. 5.7G /var/log/obsolete-flaw-checker-log/flawChecker_2019-03-19.log
  15. root@远盛09-GPU号(70-85-C2-88-27-97):/# rm -rf /var/log/obsolete-flaw-checker-log/flawChecker_2019-03-19.log
  16. root@远盛09-GPU号(70-85-C2-88-27-97):/# du -sh /var/log/obsolete-flaw-checker-log/* |grep M
  17. 657M /var/log/obsolete-flaw-checker-log/flawChecker_2019-03-19.log00000
  18. root@远盛09-GPU号(70-85-C2-88-27-97):/# rm -rf /var/log/obsolete-flaw-checker-log/flawChecker_2019-03-19.log00000
  19. root@远盛09-GPU号(70-85-C2-88-27-97):/# df -h
  20. 文件系统 容量 已用 可用 已用% 挂载点
  21. udev 3.9G 0 3.9G 0% /dev
  22. tmpfs 790M 70M 720M 9% /run
  23. /dev/sda1 32G 19G 12G 62% /
  24. tmpfs 3.9G 252K 3.9G 1% /dev/shm
  25. tmpfs 5.0M 4.0K 5.0M 1% /run/lock
  26. tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
  27. /dev/sda2 174G 46G 120G 28% /data
  28. tmpfs 1000M 370M 631M 37% /data/tmp
  29. tmpfs 790M 4.0K 790M 1% /run/user/112
  30. tmpfs 790M 0 790M 0% /run/user/1000

文件(你删除的)仍被进程占用,所以空间没释放

使用这个命令就可以查看。

  1. # lsof | grep 'deleted'
  2. # ls -ld /proc/* | grep '(deleted)'

参考链接(https://ma.ttias.be/df-command-in-linux-not-updating-actual-diskspace-wrong-data/)
以下是原文,
Caused by open file descriptors
If you delete files from the filesystem, the command “df -h” might not show the deleted space as being available. This is because the deleted files could still be held open by (defunct) processes, where the file descriptor handles still point to those files. As a result, the df command assumes the files are still there, and doesn’t clear the space.