Linux command every day must learn (34) du command _linux Shell

Source: Internet
Author: User
Tags disk usage

The Linux du command also looks at the usage space, but unlike the DF command, the Linux du command is a view of the space used by files and directory disks, or some difference from the DF command.

What's the difference between Du/bin and Du-s/bin?

-S is summary, showing the sum of space occupied by the directory

The difference is that there is a subdirectory under/bin because the/bin has no subdirectories so the results are the same, such as

DU/ETC will see a lot of output

Du-s/etc has only one line of output

1. Command format:

du [Options] [file]

2. Command function:

Displays the disk usage space for each file and directory.

3. Command parameters:

A or-all displays the size of individual files in the directory.
-B or-bytes displays the directory or file size in bytes.
-C or--total displays the sum of all directories or files in addition to the size of individual directories or files.
-K or--kilobytes is output in kilobytes (1024bytes).
-M or--megabytes is output in MB.
-S or--summarize only displays totals, listing only the last plus total value.
-H or--human-readable to k,m,g to improve the readability of the information.
-X or--one-file-xystem the file system at the start of the process, and if you encounter a different file system directory, skip.
-l< the source file size of the symbolic link specified in the symbol link > or--dereference< symbol link > Display option.
When-S or--separate-dirs displays the size of an individual directory, it does not contain the size of its subdirectories.
-x< files > or--exclude-from=< files > specify directories or files in < file >.
--exclude=< directory or File > skips the specified directory or file.
-D or--dereference-args displays the source file size for the specified symbolic link.
The-H or--si is the same as the-h parameter, but K,m,g is a unit of conversion in 1000.
-L or--count-links a file that duplicates the hardware link.

4. Use instance:

Example 1: Displays the directory or the space occupied by the file

Command:

Du

Output:

[Root@localhost test]# du
608./test6
308./test4
4./scf/lib
4./scf/service/deploy/product
4./scf/service/deploy/info
/scf/service/deploy
/scf/service
4./scf/doc
4./scf/bin
/scf
8./test3
1288.
[Root@localhost test]#

Description

Displays only the directory size of the subdirectory below the current directory and the total size of the current directory, and the bottom 1288 is the total size of the current directory

Example 2: Displays the space occupied by the specified file

Command:

Du Log2012.log

Output:

[Root@localhost test]# du Log2012.log
Log2012.log
[Root@localhost test]#

Description

Example 3: View 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
Scf/service/deploy
Scf/service
4 Scf/doc
4 Scf/bin
Scf
[Root@localhost test]#

Description

Example 4: Displays 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.gz
4 log31.tar.gz
[Root@localhost test]#

Description

Instance 5: Show only the sum size

Command:

Du-s

Output:

[Root@localhost test]# Du-s
1288.
[Root@localhost test]# du-s SCF
Scf
[Root@localhost test]# CD ...
[Root@localhost soft]# du-s Test
1288 test
[Root@localhost soft]#

Description

Example 6: Easy to read format display

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

Description

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

Description

Example 8: Displays the size of the disk space that several files or directories occupy, and also counts their totals

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

Description

With the-C option, Du shows not only the size of the two directories that occupy the disk space, but also the sum of them on the last line.

Example 9: Sort by Space size

Command:

Du|sort-nr|more

Output:

[Root@localhost test]# Du|sort-nr|more
1288.
608./test6
308./test4
/scf
/scf/service
/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]#

Description

Example 10: Output the 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]#

Description

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.