Difference between DF and Du

Source: Internet
Author: User
Tags disk usage inode usage
Document directory
  • Du command:
DF command: 

Unallocated space in the file system is used to determine the size of allocated space in the file system. For example, if a file system contains 8192 512-byte blocks and 4096 are not allocated, the allocated space is 4096-byte blocks.

Allocated space = total space-unallocated Space

Because the calculation is based on the overall file system, the DF command is the most reliable command to report the usage of the file system space.

Du command:

Is a file-oriented command that computes the space allocated to a specified file or directory. The du command must follow the target parameter and cannot isolate the file system.

For example, run the "# du/" command to calculate the space allocation information of all files in the/file system. These include all files of the/file system and files of other file systems mounted to/, such as/tmp,/var, and/usr. You can use the du command with the-x parameter to restrict operations only in the file system. However, sometimes the output results are incomplete.

The du command only calculates the space occupied by files. It does not calculate the space occupied by the file system metadata (metadata, indicating data), such as inodes, inode maps, or disk maps.

The du command only calculates the storage space occupied by accessible files. In the following two cases, the du command does not calculate the space allocated to files.

Case1:

The file is "hidden" (not a hidden file starting.
For example, if a file is stored in the/Bobby directory and a file system is installed in the/Bobby directory, the du command does not calculate the storage space occupied by files in the/Bobby directory.

Case 2:

The file is opened by other applications, and then the file is deleted. In this case, the storage space occupied by the file is maintained in the allocated State until all access to the file is disabled.
The du command does not calculate the allocated space of the file because there is no relevant record for this file in the directory. However, the DF command calculates the allocated space (see apue-> figure4.16)

 

Detailed DF command usage

A: displays the disk usage of all file systems and partitions.
I: displays the I-nodes usage.
K: The size is represented by K (default)
T: displays the disk usage of all partitions in a file system.
X: displays the disk usage of all partitions of a file system.
T: displays the file system name of each partition.
Common commands: DF-Hi

Operation Details

The reference command DF can display the maximum available space and usage of all file systems. See the following example:

# DF-H
Filesystem size used avail capacity mounted on
/Dev/ad0s1a 1.9g 389 m 1.4G 21%/
Devfs 1.0 K 1.0 K 0b 100%/dev
/Dev/ad0s1d 989 M 54 K 910 m 0%/tmp
/Dev/ad0s1f 4.8g 3.8g 657 M 86%/usr
/Dev/ad0s1e 1.9g 149 m 1.6g 8%/var
/Dev/ad0s1g 26G 890 K 24g 0%/volume2
/Dev/da0s1d 325g 261g 38g 87%/volume1

The-H parameter is added to indicate that the "human-readable" output is used, that is, the file system uses readable formats such as GB and MB.

In addition, we can also use parameter-I to view the current inode usage of the file system. Sometimes, although the file system still has space, if there is not enough inode to store the file information, it will not be able to add new files.

# DF-ih
Filesystem size used avail capacity iused ifree % iused mounted on
/Dev/ad0s1a 1.9g 389 m 1.4G 21% 20495 262127/
Devfs 1.0 K 1.0 K 0b 100% 0 0 100%/dev
/Dev/ad0s1d 989 M 62 k 910 m 0% 24 141286 0%/tmp
/Dev/ad0s1f 4.8g 3.8g 657 M 86% 311439 348015/usr
/Dev/ad0s1e 1.9g 149 m 1.6g 8% 1758 280864/var
/Dev/ad0s1g 26G 890 K 24g 0% 12 3532786 0%/volume2
/Dev/da0s1d 325g 261g 38g 87% 707277 43311409/volume1
We can see that the number of inode used in the root directory is 20495, and there are 262127 available inode.

 

 

Du: query the disk space used by an archive or directory

A: displays the disk space occupied by all directories and each file in the second directory.
B: The size is represented by bytes (the default value is K bytes)
C: add the total value (default)
S: only display the total size of each file
X: only calculate the files of the same file system.
L: Calculate the size of all files
Common commands: Du-

Operation Details
The reference command du can display the disk space occupied by all files in each directory in units of subdirectories in the specified directory (only subdirectories are displayed, but files in the specified directory are not displayed. For example:

# Du-H/etc
104 K/etc/defaults
6.0 K/etc/X11
8.0 K/etc/Bluetooth
4.0 K/etc/gnats
52 K/etc/ISDN
388 K/etc/mail
68 K/etc/mtree
2.0 k/etc/NTP
38 K/etc/PAM. d
44 K/etc/periodic/daily
6.0 K/etc/periodic/monthly
42 k/etc/periodic/security
16 K/etc/periodic/weekly
110 K/etc/periodic
6.0 K/etc/PPP
318 K/etc/rc. d
2.0 k/etc/skel
130 K/etc/ssh
10 K/etc/SSL
1.7 m/etc
The-H parameter is used to display the human-readable format. In the application, we can use the "du" command to check which directory occupies the most space. However, the output result of DU is usually very long. We can add the-S parameter to omit the subdirectories in the specified directory, and only display the total combination of the directories:

# Du-SH/etc
1.7 m/etc
When viewing the usage of the Directory, we can export the output results to the sort command for sorting to know which file has used the most space:

# Du/etc | sort-Nr | more
1746/etc
388/etc/mail
318/etc/rc. d
130/etc/ssh
110/etc/periodic
104/etc/defaults
68/etc/mtree
52/etc/ISDN
44/etc/periodic/daily
42/etc/periodic/security
38/etc/PAM. d
16/etc/periodic/weekly
10/etc/SSL
8/etc/Bluetooth
6/etc/PPP
6/etc/periodic/monthly
6/etc/X11
4/etc/gnats
2/etc/skel
2/etc/NTP
The-Nr parameter of sort indicates that reverse sorting is performed by numerical sorting. Because we want to sort the directory size, we cannot use the size output of human-readable, otherwise, the directory size may contain letters such as K and M, which may result in incorrect sorting.

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.