How to use Linux command – Du correctly

Time:2021-5-12

This article briefly introduces how to use the Linux command – Du, which can be referred to by friends who need it.

du(disk usage)

Function Description:Displays the size of the directory or file.

Grammar:Du [- abcdhhklmssx] [- L < symbolic connection >] [- x < File >] [– block size] [– exclude = < directory or file >] [– max depth = < directory level >] [– help] [– version] [directory or file]

Additional note: Du will display the disk space occupied by the specified directory or file.

Parameters:

  – A or – all    Displays the size of individual files in the directory.
  – B or – bytes    Displays the size of a directory or file in bytes.
  – C or – total    In addition to displaying the size of individual directories or files, it also displays the sum of all directories or files.
  – D or – dereference args    Displays the source file size of the specified symbolic connection.
  – H or – human readable    Take K, m, G as the unit to improve the readability of information.
  – H or – Si    It is the same as – h parameter, but K, m and G are in 1000 units.
  – K or – kilobytes    In 1024 bytes.
  – L or – count links    Repeatedly calculate the files of the hardware connection.
  – L < symbolic connection > or – dereference < symbolic connection >    Displays the source file size of the symbolic connection specified in the options.
  – M or – megabytes    The unit is 1MB.
  – S or – summarize    Only the total is displayed.
  – S or – separate dirs    When displaying the size of an individual directory, the size of its subdirectories is not included.
  – X or – one file Xsystem    It is subject to the file system at the beginning of processing, and will be omitted in case of other different file system directories.
  – X < File > or – exclude from = < File >    Specify a directory or file in file.
  – Exclude = < directory or file >    Skip the specified directory or file.
  – Max depth = < number of directory layers >    Directories that exceed the specified number of levels are ignored.
  – help    Show help.
  – version    Display version information.

example

1. Display the space occupied by the directory or file:


[[email protected] 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 .

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

Displays the space occupied by the specified file:


[[email protected] test]# du log2012.log
300 log2012.log

3. To view the space occupied by the specified directory:


[[email protected] 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

4. Display space occupied by multiple files:

[[email protected] test]# du log30.tar.gz log31.tar.gz
4 log30.tar.gz
4 log31.tar.gz

Only display the size of the sum:
[[email protected] test]# du -s
1288 .

[[email protected] test]# du -s scf
32 scf

[[email protected] test]# cd ..
[[email protected] soft]# du -s test
1288 test

The above is the whole content of this article, I hope to help you learn, and I hope you can support developer more.