[Turn]linux du and DF commands

Source: Internet
Author: User
Tags disk usage

Transferred from: http://blog.csdn.net/kmesg/article/details/6570800

Today, some classmates asked me to look at the directory size under Linux command, now also will be the former learning to DU/DF two command summary of it.
In the pre-test work, we have encountered the DF and du two commands because of the fact that the program cannot be executed due to the full disk space.

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), and-m shows the size of the directory in megabytes (-k/-g is KB/GB, of course).
For more information, it's Man Du and Mans df.

Du-estimate File Space usage
Summarize disk usage of each FILE, recursively for directories.

Df-report file system disk space usage
Show information about the file system in which each file resides, or all file systems by default.
DF Displays the amount of disk space available on the file system containing each file nameargument. If no file name is given, the space available on all currently mounted file systems are shown.

du
Du's English is: disk usage, meaning the use of space, the function is to step into each subdirectory of the specified directory and show that the directory occupies the file system data block, if no directory is specified, the current directory is counted.
The command options for du have the following meanings:

A: Displays the disk space occupied by all directories and each file under the second directory
S: Show only the sum of each file size
B: Size is indicated by bytes.
X: Skipping directories on different file systems is not counted
A: Recursively displays the number of data blocks in each file in the specified directory and the files in the descendant directory
...
Use du for viewing
[Email protected]:/home/htmlfile# du
/test.
/BBB.
84.

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.

DF
Unlike Du, du is a file-oriented command that calculates only the space occupied by the file. Does not calculate the space occupied by the file system metadata. DF is calculated based on the overall file system, which determines the size of the allocated space in the system through unallocated space in the file system. The DF command can get how much space the hard disk occupies and how much space is left, and it can also show the usage of all file systems on the I node and disk blocks.

The DF command has the following meanings for each selection:

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. When splitting a 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 the same size of the hard disk will have more files, that is to say, more inode to hang files and directories

[Turn]linux du and DF commands

Related Article

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.