Analysis of difference between DF and du command output under Linux

Source: Internet
Author: User

PS: Some time ago, children's shoes asked me, why his server with DF and du command query file size display is different. In fact, these two command query principle is not the same, the following is a brief analysis:


1, under normal circumstances, DF and du output results will have a gap

The Du-sh command increments the total number of blocks used by the file system by adding the number of blocks used by all directories, symbolic links, and files in the specified file system.

The DF command, by viewing the file system disk block allocation graph, draws the total number of blocks and the remaining blocks.

File system allocation Some of the disk blocks used to record some of its own data, such as I node, disk distribution map, indirect blocks, super blocks and so on. This data is not visible to most user-level programs, often referred to as meta data.

The du command is a user-level program that does not take meta data into account, while the DF command looks at the file system's disk allocation diagram and considers meta data.

As a result, DF calculates a used space that is slightly larger than the results of the DU calculation.


2, under abnormal circumstances, DF calculation used space will be much larger than du

This is also the problem encountered before, DF View results File system 100% used, and Du's result is also 6GB idle, so a problem hardware manufacturers a support incredibly do not know how to explain, this is also let me curious to check back at night to see the reason, the results of Google a bit.

The reason for this is that Du is used for computing space based on the file name and directory name, and DF is used to calculate space using hard disk block usage.

When an application is writing a large file, we RM or mv the file (Unix is allowed to do so, Windows is silly at this point), the application takes possession of the handle, and according to the location of the disk where the handle refers to write the disk directly, and does not check whether the file is deleted.

Therefore, the above problems will arise. Specific to the Oracle level, this can happen: Oracle for some reason in generating a large trace file, may cause the Oracle and other catalogs full, if the direct RM or MV off the trace file will find that the space is not released, This could lead to an Oracle database down-machine.

Workaround: Use the "> tracefile.trc" command to empty the file, if you need to keep the trace file for later analysis of the problem, you can use the CP first copy the file to other places, and then empty the original file.


The output difference between DF and Du is explained in the original text as follows:

Problem Definition

This section gives the technical explanation of what du and DF sometimes report
Different totals of disk space usage.

When a program which is running in the background writes to a file while the
Process is running, and the file to which this process was writing is deleted.
Running DF and du shows a discrepancy in the amount of disk space usage. The
DF command shows a higher value.

Explanation Summary

When your open a file, you get a pointer. Subsequent writes to this file
References this file pointer. The write call does is not a check to see if the file
Is there or not. It just writes to the specified number of characters starting
At a predetermined location. Regardless of whether the file exist or not, disk
Blocks is used by the write operation.

The DF command reports the number of disk blocks used, while du goes through the
File structure and reports the number of blocks used by each directory. As
Far as Du was concerned, the file used by the process does not exist, so it does
Blocks used by this phantom file. But DF keeps track of disk blocks
Used, and it reports the blocks used by this phantom file.

More wonderful Linux video tutorials at 51CTO Academy: http://edu.51cto.com/course/courseList/id-48.html

Analysis of difference between DF and du command output under Linux

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.