|
Du command, namely, disk usage, file or directory can calculate the disk space occupied.
Format:
du [options] [file]
du [OPTION] ... [FILE] ...
No option is specified, it will measure the current working directory and all its subdirectories, respectively display the amount of space each directory, and finally display the working directory of the total space.
Command Options:
-a, -all
It includes all files, not just directories
-B, -block-Size = SIZE use SIZE-byte blocks
-b, -bytes bytes for the unit
-k, in kilobytes (KB) for the unit
-m, in megabytes (M) for the unit
-c, -total plus a final total (default)
-D, -dereference-Args
dereference FILEs that are symbolic links
-H With - -si same effect.
-h, -human-readable way to compare the reading output file size information (for example, 1K 234M 2G). Note: This option in many other commands (df, ls) is also effective.
-si -h with the same effect, just as in 1000 in terms of unit
-l, -count-links to calculate the size of all the files on the hard link file, the calculation times.
-L, -dereference Display options are symbolic links to specify the size of the source file.
-P, -no-Dereference do not follow any symbolic links (default)
-S, -separate-Dirs do not include size of subdirectories when calculating the space occupied by the directory.
-s, -summarize working directory displays only the total space
-x, -one-file-system to start processing a file system prevail, when there are other different file system directory is skipped.
-X FILE, -exclude-from = FILE exclude specified FILE
-exclude = PATTERN exclude files that meet the style, Pattern Shell is the ordinary style? Represent any one character, * represents any number of characters.
-max-depth = N
List only depth is less than max-depth directory and file information -max-depth = 0 when the effect is the same as with -s
Example:
Example 1: Display directory or file uses less space
command:
du
Output:
[Root @ localhost test] # du
608 ./test6
308 ./test4
4 ./scf/lib
4 ./scf/service/deploy/product
4 ./scf/service/deploy/info
12 ./scf/service/deploy
16 ./scf/service
4 ./scf/doc
4 ./scf/bin
32 ./scf
8 ./test3
1288.
Explanation:
Show only the total size of the total size of the current directory and subdirectories of the current directory size directory, the bottom of the current directory 1288
Example 2: Specify file takes
command:
du log2012.log
Output:
[Root @ localhost test] # du log2012.log
300 log2012.log
[Root @ localhost test] #
Example 3: Check the space occupied by the specified directory
command:
du scf
Output:
[Root @ localhost test] # du scf
4 scf / lib
4 scf / service / deploy / product
4 scf / service / deploy / info
12 scf / service / deploy
16 scf / service
4 scf / doc
4 scf / bin
32 scf
[Root @ localhost test] #
Example 4: displaying a plurality of the space occupied by the file
command:
du log30.tar.gz log31.tar.gz
Output:
[Root @ localhost test] # du log30.tar.gz log31.tar.gz
4 log30.tar.gz
4 log31.tar.gz
[Root @ localhost test] #
Example 5: Displays total size
command:
du -s
Output:
[Root @ localhost test] # du -s
1288.
[Root @ localhost test] # du -s scf
32 scf
[Root @ localhost test] # cd ..
[Root @ localhost soft] # du -s test
1288 test
[Root @ localhost soft] #
Example 6: easy to read format
command:
du -h test
Output:
[Root @ localhost soft] # du -h test
608K test / test6
308K test / test4
4.0K test / scf / lib
4.0K test / scf / service / deploy / product
4.0K test / scf / service / deploy / info
12K test / scf / service / deploy
16K test / scf / service
4.0K test / scf / doc
4.0K test / scf / bin
32K test / scf
8.0K test / test3
1.3M test
[Root @ localhost soft] #
Example 7: files and directories are displayed
command:
Output:
[Root @ localhost soft] # du -ah test
4.0K test / log31.tar.gz
4.0K test / test13.tar.gz
0 test / linklog.log
0 test / test6 / log2014.log
300K test / test6 / linklog.log
0 test / test6 / log2015.log
4.0K test / test6 / log2013.log
300K test / test6 / log2012.log
0 test / test6 / log2017.log
0 test / test6 / log2016.log
608K test / test6
0 test / log2015.log
0 test / test4 / log2014.log
4.0K test / test4 / log2013.log
300K test / test4 / log2012.log
308K test / test4
4.0K test / scf / lib
4.0K test / scf / service / deploy / product
4.0K test / scf / service / deploy / info
12K test / scf / service / deploy
16K test / scf / service
4.0K test / scf / doc
4.0K test / scf / bin
32K test / scf
4.0K test / log2013.log
300K test / log2012.log
0 test / log2017.log
0 test / log2016.log
4.0K test / log30.tar.gz
4.0K test / log.tar.bz2
4.0K test / log.tar.gz
0 test / test3 / log2014.log
4.0K test / test3 / log2013.log
8.0K test / test3
4.0K test / scf.tar.gz
1.3M test
[Root @ localhost soft] #
Example 8: Several display each file or directory size of disk space occupied, but also their statistical sum
command:
du -c log30.tar.gz log31.tar.gz
Output:
[Root @ localhost test] # du -c log30.tar.gz log31.tar.gz
4 log30.tar.gz
4 log31.tar.gz
8 Total
[Root @ localhost test] #
Explanation:
Plus -c option, du shows not only takes up two directories each the size of disk space, is also the last line of statistics their sum.
Example 9: Sort by space
command:
du | sort -nr | more
Output:
[Root @ localhost test] # du | sort -nr | more
1288.
608 ./test6
308 ./test4
32 ./scf
16 ./scf/service
12 ./scf/service/deploy
8 ./test3
4 ./scf/service/deploy/product
4 ./scf/service/deploy/info
4 ./scf/lib
4 ./scf/doc
4 ./scf/bin
[Root @ localhost test] #
Example 10: Output space used by each subdirectory under the current directory
command:
du -h --max-depth = 1
Output:
[Root @ localhost test] # du -h --max-depth = 1
608K ./test6
308K ./test4
32K ./scf
8.0K ./test3
1.3M.
[Root @ localhost test] # |
|
|
|