The du and df commands show different amounts of available disk space. What is happening?
You need to figure out what the du and df commands actually do.du traverses the directory tree, measuring how much space each file takes up, and gives you the total space.
df simply queries the file system for the remaining volume. It looks like the same thing, however a file with no directory entries will affect df but will not affect du.
When a program uses a file and you delete it, the file is not actually removed from the file system until the program stops using it. However, the file is immediately removed from the directory listing. You can easily see this with a program like more.
Suppose you have a file so large that its presence affects the output of the du and df commands. (Since disks can be so large nowadays, it could be a very large file!) If you delete the file while more is working on it, the more command is not affected, nor does it report that it cannot view the file. The file entry is simply removed from the directory, so other programs or users will not be able to access it.
du will show that the file is gone - it's browsing the directory tree and the file won't be there.
df shows that it's still there, since the file system knows that more is still using that space.
Once you are done with more, the du and df commands will come into alignment.
Note that the Soft Updates subsystem may delay the release of disk space; you may have to wait up to 30 seconds before the changes are noticed!
28 Apr 2024, 18:32:10