Linux du and df commands

Source: Internet
Author: User

Linux du and df commands

Some people asked me about the command for viewing the directory size in Linux. Now I want to summarize the two commands du/df I learned a while ago. In the past, the df and du commands were used because the program could not be executed due to the full disk space.

View the directory size in du, and view the disk usage in df.
Commands that I often use (if necessary, sudo uses the root permission ),
1. view the size of a directory: du-hs/home/master/documents ents
View the sizes of all directories in the directory and sort them in descending order: sudo du-sm/etc/* | sort-nr | less
2. view disk usage (File System usage): sudo df-h
Df -- block-size = GB

-H is used to make the output result easier for humans to read. du-s only displays the total usage of directories (not showing the subdirectories separately ), -m Displays the directory size in MB (of course-k/-g is KB/GB ).
For more information, see man du and man 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 on 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 is shown.

 

 

Du
Du: disk usage, which indicates disk space usage. The function is to enter each subdirectory of a specified directory step by step and display the usage of the directory's file system data blocks, if no directory is specified, the current directory is counted.
The meaning of each option of the du command is as follows:

A: displays the disk space occupied by all directories and each file in the second directory.
S: only display the total size of each file
B: The size is represented by bytes.
X: Skipping directories on different file systems is not counted.
A: recursively display the number of data blocks occupied by each file in the specified directory and its descendants
...
View with du
Root @ bkjia:/home/htmlfile # du
16./test
60./bbb
84.

The first column is the disk space capacity in blocks, and the second column lists the directory names that use the space in the directory.

1) view the size of subdirectories in the current directory
Root @ bkjia:/home/htmlfile # du-sm.
1.
The "." Of du-sm. indicates the current directory.

2) view the size of the current directory and subdirectory
Root @ bkjia:/home/htmlfile # du-h
16 K./test
60 K./bbb
84 K.
-H indicates the use of K, M, G humanized display.

3) view the size of the bbb directory in the current directory, but do not want to view other directories or subdirectories.
Root @ bkjia:/home/htmlfile # du-ch bbb | tail-n 1
60 K total
The MPs queue contains the du and tail commands.-c indicates the sum of the sizes of the listed directories.

4) list the sizes of all directories and files in the current directory
Root @ bkjia:/home/htmlfile # du-ah bbb
4.0 K bbb/mysql. php
4.0 K bbb/index.htm
4.0 K bbb/p. php
28 K bbb/memcache. php
12 K bbb/. session. php. swp
4.0 K bbb/hello.html
60 K bbb
-A indicates that the directory and file are included.

5) List Directory and subdirectory size without line breaks
Root @ bkjia:/home/htmlfile # du-0 h
16 K./test60K./bbb84K. root @ bkjia:/home/htmlfile #
"-0" indicates that a line break is not followed, and the second line is output.

Df
Unlike du, du is a file-oriented command that only calculates the space occupied by files. Do not calculate the space occupied by the file system metadata. Df is calculated based on the file system population. No space is allocated in the file system to determine the size of allocated space in the system. The df command can obtain the space occupied by the hard disk and the remaining space. It can also display the I node and disk block usage of all file systems.

The options of the df command are as follows:

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.
....

View with df

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 64 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 hard disk partition corresponding to the file system.
The second row is the data of the data block contained in the partition (1 Database is 1024 bytes)
The fourth row is an array of used and unused data blocks.
The fifth line is the percentage of space used by normal users.
The sixth line is the file system Installation Point.

The addition of the used and unused data blocks in the third and fourth rows is not equal to the total data blocks in the second row, because the partition leaves a small amount of space

Used by the system administrator.

1)
[Email protected]: ~ $ Df-h
File System capacity used available % mount point
/Dev/cciss/c0d0p1 2.0G 598 M 1.3G 32%/
Tmpfs 1014 M 4.0 K 1014 M 1%/lib/init/rw
Udev 10 M 64 K 10 M 1%/dev
Tmpfs 1014 M 4.0 K 1014 M 1%/dev/shm
/Dev/cciss/c0d0p9 125G 42G 83G 34%/home
/Dev/cciss/c0d0p7 2.0G 68 M 2.0G 4%/tmp
/Dev/cciss/c0d0p8 4.0G 1.7G 2.1G 45%/usr
/Dev/cciss/c0d0p6 2.0G 333 M 1.6G 18%/var
-H indicates the use of K, M, G humanized display.

2)
[Email protected]: ~ $ Df-ia
File System Inode (I) used (I) available (I) used % mount point
/Dev/cciss/c0d0p1 262752 60150 202602 23%/
Tmpfs 224142 10 224132 1%/lib/init/rw
Proc 0 0 0-/proc
Sysfs 0 0 0-/sys
Procbususb 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 54 262698 1%/tmp
/Dev/cciss/c0d0p8 524832 35743 489089 7%/usr
/Dev/cciss/c0d0p6 262752 4896 257856 2%/var
Inode is the basic information used to store files and directories, including the time, file name, user, and group. When dividing a sector, the system will first make a bunch of inode for later use. 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 stored are small, there will be a large number of files in hard disks of the same size, that is, a large number of inode are required to mount files and directories.

This article permanently updates the link address:

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.