Linux uses du and DF command results inconsistent

Source: Internet
Author: User
Tags readable disk usage


Linux typically uses the Du and DF commands to see disk space usage, with the following basic syntax:
Df-report file system disk space USAGEDF [OPTION] ... [File]...-h,--human-readable              print sizes in human readable format (e.g., 1K 234M 2G) du-estimate FILE space usagedu [OPTION] ... [File]...-h,--human-readable              print sizes in human readable format (e.g., 1K 234M 2G)-S,--summarize              display only A total for each argument



The root cause of inconsistent disk space statistics obtained by the DF and Du commands is to open the file descriptor (although the file has been deleted and other processes may have opened the file), and the scenario is modeled as follows:
1. Disk usage prior to start:[email protected]:~$ df-h/Home
Filesystem Size used Avail use% mounted on
/DEV/SDA1 6.8G 6.3G 196M 98%/
[Email protected]:~$ du-sh/home
2.2G /Home
2. Another terminal through VI, open test.iso (size 700M or so);
[Email protected]:~$ lsof | grep ISO
vi 21350 Vonzhou 3r REG 8,1 741343232 325789/home/vonzhou/test.iso
3. Delete this more than 700 m file Test.iso from the current terminal;
[Email protected]:~$ rm test.iso
4. The statistics of DF are not changed at this time, but du does not count it, because the current directory does not have test.iso this file, but there is a process to hold its open file descriptor, so the file system still exists.
[email protected]:~$ df-h/home
filesystem      size  Used Avail Use% Mounted on
/dev/sda1       6.8g  6.3g   196m   98%/
[email protected]:~$ du-sh/home
Span style= "Background-color:rgb (204,204,204)" >1.5g       /Home
[email protected]:~$ lsof | grep iso
vi        21350     vonzhou    3r      reg         8,1 741343232  325789/home/vonzhou/test.iso (deleted)
5. Stop VI to take possession of the file, and look at the use of disk space again, this is the two show a consistent state:[email protected]:~$ lsof | grep iso[email protected]:~$ df-h/Home
Filesystem Size used Avail use% mounted on
/DEV/SDA1 6.8G 5.6G 903M 87%/
[Email protected]:~$ du-sh/home
1.5G /Home

Summary : This inconsistency occurs because DF and du use different mechanisms to get disk space usage,du seems more accurate and real-time, each time you run the command, will recursively traverse all the files under that path to calculate the space size, Of course the speed will be slower. DF relies on the information of the Super block, which counts those files that are in memory but not on disk, and the index file and metadata are counted, so you see that the DF display has a higher usage rate than du . So normally, choose to use the du command.

Linux uses du and DF command results inconsistent

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.