The difference and relation between Du and DF in Linux

Source: Internet
Author: User
Tags disk usage

1, the difference between the two
Du,disk usage, is to calculate the size of each file by searching for files and then add up, du can see the files are just some currently exist
, and it has not been deleted. The size of his calculations is the cumulative sum of all the file sizes that he currently thinks exist.
Df,disk free, through the file system to quickly get information about the size of the space, when we delete a file, this file does not
is immediately disappear in the file system, but temporarily disappear, when all the programs are not used, will be released according to the rules of the OS
After deleting the file, DF records the size of the file obtained by the file system, and he is better than the du strong place to be able to see the deleted
File, and the size of the calculation, this part of the space is added, more accurate.
When the file system also determines that the file has been deleted, the Du and DF coincide.

2,du View the directory size, DF to view disk usage.
I often use commands (sudo uses root privileges, if necessary),
1). View the size of a directory: du-hs/home/master/documents
View the size of all directories under the directory and sort by size descending: sudo du-sm/etc/* | Sort-nr | Less
2). View disk usage (file system usage): sudo df-h
DF--BLOCK-SIZE=GB
-H is to make the output easier for human reading; Du-s only shows the total usage of the directory (not showing each subdirectory separately),-M is
MB shows the size of the directory (of course-k/-g is KB/GB).

3,du Use a detailed case
A: Displays the disk space occupied by all directories and each file in the second directory
S: Only the sum of each file size
B: Size is represented by bytes
x: Skipping directories on different file systems no statistics
A: Recursively displays the number of data blocks in each file in the specified directory and the files in the Descendants directory
...
View with du
[email protected]:/home/htmlfile# du
/test
./BBB
.

The first column is the amount of disk space in blocks, and the second column lists the directory names that use these spaces in the directory
1) View the size of the current directory containing subdirectories
[Email protected]:/home/htmlfile# du-sm.
1.
One of the DU-SM. of "." Represents the current directory.
2) View the size of the current directory and subdirectories
[Email protected]:/home/htmlfile# du-h
16K./test
60K./bbb
84K.
Where-H means display in a humane form using k,m,g.
3) See the BBB directory size in the current directory, but do not want to see other directories and subdirectories
[Email protected]:/home/htmlfile# du-ch BBB | Tail-n 1
60K Total
The pipeline contains the Du and tail two commands, and the-C means that the sum of the size of the listed directories is finally computed.
4) List the size of all directories and files in the current directory
[Email protected]:/home/htmlfile# du-ah BBB
4.0K bbb/mysql.php
4.0K bbb/index.htm
4.0K bbb/p.php
28K bbb/memcache.php
12K BBB/.SESSION.PHP.SWP
4.0K bbb/hello.html
60K BBB
Where-a means containing directories and files
5) Do not change the column out of the directory and the size of the sub-directory information
[Email protected]:/home/htmlfile# du-0h
16K./test60k./bbb84k [Email protected]:/home/htmlfile#
Where 0 means that a message is listed without a newline, followed by a second message.

4,DF detailed case
A: Displays all file systems and disk usage scenarios for each partition
I: Show the usage of i-nodes
K: size is denoted by K (default value)
T: Displays all partition disk usage for one file system
X: Displays all partitions that are not part of a file system disk usage
T: Displays the name of the file system to which each partition belongs
Using DF for viewing
Filesystem 1k-blocks used Available use% mounted on
/dev/cciss/c0d0p1 2068156 611572 1351528 32%/
TMPFS 1038080 4 1038076 1%/LIB/INIT/RW
Udev 10240 10176 1%/dev
TMPFS 1038080 4 1038076 1%/DEV/SHM
/DEV/CCISS/C0D0P9 130700120 44034236 86665884 34%/Home
/DEV/CCISS/C0D0P7 2068156 68932 1999224 4%/tmp
/DEV/CCISS/C0D0P8 4132372 1760620 2161840 45%/usr
/DEV/CCISS/C0D0P6 2068156 330104 1632996 17%/var
The first line is the disk partition for the file system.
The second row is the data for the chunk that the partition contains (1 database is 1024 bytes)
Line 34th is an array of used and unused blocks of data
Row Five is the percentage of normal user space usage
Line Six is the installation point of the file system
Where line 34th has been used and unused chunks of data are not equal to the second row of total blocks of data, because the partition leaves a small amount of space available to
Used by system administrators.
1)
[Email protected]:~$ df-h
File system capacity has been used with available% mount points
/dev/cciss/c0d0p1 2.0G 598M 1.3G 32%/
Tmpfs 1014M 4.0K 1014M 1%/LIB/INIT/RW
Udev 10M 64K 10M 1%/dev
Tmpfs 1014M 4.0K 1014M 1%/DEV/SHM
/DEV/CCISS/C0D0P9 125G 42G 83G 34%/Home
/DEV/CCISS/C0D0P7 2.0G 68M 2.0G 4%/tmp
/DEV/CCISS/C0D0P8 4.0G 1.7G 2.1G 45%/usr
/DEV/CCISS/C0D0P6 2.0G 333M 1.6G 18%/var
Where-H means display in a humane form using k,m,g.
2)
[Email protected]:~$ Df-ia
File System Inode (i) Used (i) available (i)% mount point used
/dev/cciss/c0d0p1 262752 60150 202602 23%/
Tmpfs 224142 224132 1%/LIB/INIT/RW
Proc 0 0 0-/proc
Sysfs 0 0 0-/sys
Procbususb 0 0 0-/proc/bus/usb
Udev 224142 770 223372 1%/dev
TMPFS 224142 3 224139 1%/DEV/SHM
Devpts 0 0 0-/dev/pts
/DEV/CCISS/C0D0P9 130763968 1972907 128791061 2%/Home
/DEV/CCISS/C0D0P7 262752 262698 1%/tmp
/DEV/CCISS/C0D0P8 524832 35743 489089 7%/usr
/DEV/CCISS/C0D0P6 262752 4896 257856 2%/var
The so-called Inode is the basic information for storing files and directories, including time, file names, users and groups. In the split sector
, the system makes a bunch of inode for later use, and the number of inode is related to the total number of files and directories that can be created in the system.
If most of the files to be saved are very small, then there will be more files in the same size hard disk, which means more inode is needed to hang
Archives and catalogues

The difference and relation between Du and DF in 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.