A user logged on to the Linux system server to view the time, unexpectedly found that DF and du check out the results are not the same, du check out the "actual use of space" is significantly more than DF to check out the use of space is much smaller, this is how is it? Is there some space hidden away? Here's what df and Du commands have found to be different solutions for using space.
The method is as follows:
First, we use DF to view the used space:
From the figure above, the root partition has been used 5456700KB (contract 5.20GB).
We then use Du to identify the size of each directory under the root partition:
Excluding two directories in the red box (because they are mounted), the total size of all directories is 3075332KB (contract 2.93GB), which is much smaller than DF detected 2.27GB.
Why is there so much less space?
It's because we deleted some of the files that were being written by the process, and although we've deleted them, as long as the process is still there, that file will not be deleted, but it is temporarily stored somewhere in the system, a bit like a Windows Recycle Bin.
To solve this problem, the simplest is to restart the server, but the production environment generally will not be easy to restart, so we can solve by other means.
First use the lsof command with the grep command to find out what has been deleted, but still occupy the system space "rogue".
The file in the red box above is just a big file I deleted before, and I'm now trying to reboot the program (node) and I kill the process directly because I started it automatically, so I don't have to start it manually.
The use of space has suddenly dropped to 3226324KB (contract 3.08GB), has been very close to the total space du statistics.
Next, I restarted the other deleted files one by one, and eventually DF was about the same size as the du statistic.
In this way, it solves the different documents of DF and Du, and drives away the "rogue" in the system, and returns the space that belongs to us.
DF and Du commands to check out the use of a different space to solve the problem here, as you also have this problem can follow the above steps to operate, so as to solve problems.