The difference between DF and du under Linux __linux

Source: Internet
Author: User
The DF command is the overall disk usage that lists the file system How to use commandDF [-ahikhtm] [directory or filename] parameter:-A lists all file systems--------Displays file systems in KB capacity-M with MB capacity
-h Displays (important) in a format that is more readable in GB, MB, KB, etc.
-H conversion to m=1000k instead of m=1024k-T and the document system name of the partition (such as EXT3) also lists the number of inode for-I, not the capacity of the hard disk to display

du [-ahskm] file or directory name-a list all files and directory capacity-H to display the total number of s in GB, MB, KB, and so on.-K to display file systems in KB capacity-M to display file systems in MB
If a file or directory is omitted, the current directory is used by default

when we use the Du and DF commands, we sometimes find that the difference in the display is larger. When a process writes to a file, it first gets a pointer to the file and then writes to the disk. This pointer is used for subsequent writes to the file, but the write does not check to see if the file exists. It will only continue to write to the already-determined disk block. DF Command checks the use of disk blocks, however the du command checks the file system and then counts the blocks used by each directory. Because of this feature of the Du command, when a process occupies a file that does not exist, it does not count the disk blocks that the files occupy. However, the DF command keeps track of the disk blocks used and then reports the use of the disk blocks. If you are interested, take a look at the following article------------------

This is article explains how reporting disk usage du and reporting free disk spaces
On file systems DF different numbers.

Du
--

The du user command gives the number of kilobytes contained in all files and,
Recursively, directories within each specified directory or file (filename).
If filename is missing, '. '  (The current directory) is used. A file which
has multiple links to it are only counted once.

EXAMPLE:

System% du

5./jokes
/squash.
/tech.papers/lpr.document
217./tech.papers/new.manager
401./tech.papers
144./memos
/letters.
388./window
/messages.
/useful.news
1211.

Note This last number, 1211 are the grand total (in kilobytes) for the
Directory.

Df
--

The DF User command displays the following information:

Amount of disk spaces occupied by currently mounted file systems
The amount of used and available spaces
How much of the file system "s total capacity has been used

Used without arguments, DF reports on all mounted file systems.

EXAMPLE:

System% DF

FileSystem Kbytes used avail capacity mounted on
/dev/ip0a 7445 4714 1986 70%/
/dev/ip0g 42277 35291 2758 93%/usr

note:used plus avail is less than the amount of spaces in the file system
(kilobytes) because the system reserves a fraction of the spaces in the file
System to allow it allocation routines to work. The amount reserved is
Typically about 10%.  (This may is adjusted using the Tunefs command.) Refer to
The man's pages on Tunefs (8) For more information.) When all the spaces on a file
System, except for this reserve, being in use, only the super-user can allocate
New files and data blocks to existing files. This is however, may cause the file
System to is over allocated. When a file system was over allocated in this way,
DF May, the file system is more than 100% utilized.

If arguments to DF are disk partitions (for example,/dev/ip0as or path names),
DF produces a on the file system containing the named file. Thus, DF
Shows the amount of spaces on the file system containing to the current directory.

Problem Definition
------- ----------

This section gives the technical explanation of why Du and DF sometimes
Different totals of disk space usage.

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

Explanation Summary
----------- -------

When you are open a file, you get a pointer. Subsequent writes to this file
References this file pointer. The Write call does don't check to the 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 are used by the write operation.

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

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.