Linux Command Tutorial: view disk space using the du command

Source: Internet
Author: User

Linux Command Tutorial: view disk space using the du command
The du command, that is, disk usage, can calculate the disk space occupied by files or directories. Command Format:

Du [Option] [file]
Du [OPTION]… [FILE]…

If no option is specified, it measures the current working directory and all its subdirectories, displays the space occupied by each directory, and displays the total space occupied by the working directory. Command Options:

-A,-all
Including all files, not just directories.
-B,-block-size = SIZE use SIZE-byte blocks
-B,-bytes in bytes
-K, measured in kilobytes (KB)
-M, measured in MB
-C,-total Add a total (system default)
-D,-dereference-args
Dereference FILEs that are symbolic links
-H has the same effect as--si.
-H,-human-readable outputs the file size information in a comparative manner (for example, 1 K 234 M 2G ). Note: This option is also valid in many other commands (df, ls.
-Si has the same effect as-h, but the conversion unit is 1000.
-L,-count-links calculates the size of all files. for hard-linked files, the calculation is performed multiple times.
-L,-dereference: Specifies the size of the source file connected by the symbol in the display option.
-P,-no-dereference does not follow any symbol connection (default)
-S,-separate-dirs do not include the size of sub-directories when calculating the space occupied by directories.
-S,-summarize only displays the total space occupied by the working directory
-X,-one-file-system is based on the file system at the beginning of processing. If it encounters a different file system directory, it is skipped.
-X file,-exclude-from = FILE to exclude the specified FILE
-Exclude = PATTERN: exclude files that conform to the style. Pattern is a normal Shell style ,? Represents any character. * represents any number of characters.
-Max-depth = N
Only list the Directory and file information with a depth less than max-depth-when max-depth = 0, the effect is the same as that of-s.

Instance used:

Instance 1: displays the space occupied by directories or files.

Command:

Du

Output:

[root@localhost test]# du608     ./test6308     ./test44       ./scf/lib4       ./scf/service/deploy/product4       ./scf/service/deploy/info12      ./scf/service/deploy16      ./scf/service4       ./scf/doc4       ./scf/bin32      ./scf8       ./test31288    .

Note:

Only the directory size of the subdirectories under the current directory and the total size of the current directory are displayed. The bottom 1288 is the total size of the current directory.

Instance 2: displays the space occupied by the specified file

Command:

Du log2012.log

Output:

[root@localhost test]# du log2012.log 300     log2012.log[root@localhost test]#

Instance 3: view the space occupied by the specified directory

Command:

Du scf

Output:

[root@localhost test]# du scf4       scf/lib4       scf/service/deploy/product4       scf/service/deploy/info12      scf/service/deploy16      scf/service4       scf/doc4       scf/bin32      scf[root@localhost test]#

Example 4: display the space occupied by multiple files

Command:

Du log30.tar.gz log31.tar.gz

Output:

[root@localhost test]# du log30.tar.gz log31.tar.gz 4       log30.tar.gz4       log31.tar.gz[root@localhost test]#

Instance 5: only show the total size

Command:

Du-s

Output:

[root@localhost test]# du -s1288    .[root@localhost test]# du -s scf32      scf[root@localhost test]# cd ..[root@localhost soft]# du -s test1288    test[root@localhost soft]# 

Example 6: easy-to-read format display

Command:

Du-h test

Output:

[root@localhost soft]# du -h test608K    test/test6308K    test/test44.0K    test/scf/lib4.0K    test/scf/service/deploy/product4.0K    test/scf/service/deploy/info12K     test/scf/service/deploy16K     test/scf/service4.0K    test/scf/doc4.0K    test/scf/bin32K     test/scf8.0K    test/test31.3M    test[root@localhost soft]# 

Instance 7: Both files and directories are displayed.

Command:

Output:

[root@localhost soft]# du -ah test4.0K    test/log31.tar.gz4.0K    test/test13.tar.gz0       test/linklog.log0       test/test6/log2014.log300K    test/test6/linklog.log0       test/test6/log2015.log4.0K    test/test6/log2013.log300K    test/test6/log2012.log0       test/test6/log2017.log0       test/test6/log2016.log608K    test/test60       test/log2015.log0       test/test4/log2014.log4.0K    test/test4/log2013.log300K    test/test4/log2012.log308K    test/test44.0K    test/scf/lib4.0K    test/scf/service/deploy/product4.0K    test/scf/service/deploy/info12K     test/scf/service/deploy16K     test/scf/service4.0K    test/scf/doc4.0K    test/scf/bin32K     test/scf4.0K    test/log2013.log300K    test/log2012.log0       test/log2017.log0       test/log2016.log4.0K    test/log30.tar.gz4.0K    test/log.tar.bz24.0K    test/log.tar.gz0       test/test3/log2014.log4.0K    test/test3/log2013.log8.0K    test/test34.0K    test/scf.tar.gz1.3M    test[root@localhost soft]# 

Instance 8: displays the disk space occupied by several files or directories, and calculates the sum of these files and directories.

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] #

Note:

After the-c option is added, du not only displays the disk space occupied by the two directories, but also calculates the sum of these two directories in the last row.

Instance 9: sort by space size

Command:

Du | sort-nr | more

Output:

[root@localhost test]# du|sort -nr|more1288    .608     ./test6308     ./test432      ./scf16      ./scf/service12      ./scf/service/deploy8       ./test34       ./scf/service/deploy/product4       ./scf/service/deploy/info4       ./scf/lib4       ./scf/doc4       ./scf/bin[root@localhost test]# 

Example 10: output the space used by each subdirectory in the current directory

Command:

Du-h -- max-depth = 1

Output:

[root@localhost test]# du -h  --max-depth=1608K    ./test6308K    ./test432K     ./scf8.0K    ./test31.3M    .[root@localhost test]#

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.