Linux common commands: du command

  The Linux du command also checks the space used, but unlike the df command, the Linux du command checks the space used by the file and directory disk, or it is somewhat different from the df command.

1. Command format:

  du [options] [files]

2. Command function:

  Displays the disk space used by each file and directory.

3. Command parameters:

-a or -all Display the size of individual files in the directory.   

-b or -bytes Display directory or file size in bytes.   

-c or --total In addition to displaying the size of individual directories or files, also display the sum of all directories or files. 

-k or --kilobytes Output in KB (1024bytes).

-m or --megabytes Output in MB.   

-s or --summarize only display totals, only the last summed value.

-h or --human-readable Use K, M, G as units to improve the readability of information.

-x or --one-file-xystem is based on the file system at the beginning of processing, and skips it if it encounters other different file system directories. 

-L<symlink> or --dereference<symlink> Displays the source file size of the symlink specified in the options.   

-S or --separate-dirs Display the size of an individual directory without the size of its subdirectories. 

-X <file> or --exclude-from=<file> Specify a directory or file in <file>.   

--exclude=<directory or file> Skip the specified directory or file.    

-D or --dereference-args Display the source file size of the specified symlink.   

-H or --si Same as the -h parameter, but K, M, G are in 1000 units.   

-l or --count-links Repeats the count of hardware linked files.  

4. Example of use:

Example 1: Display the space occupied by a directory or file 

Order:

  from

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    .

[root@localhost test]#

illustrate:

  Only display the directory size of the subdirectories under the current directory and the total size of the current directory, the bottom 1288 is the total size of the current directory

 

Example 2: Display the space occupied by the specified file

Order:

  du log2012.log

output:

[root@localhost test]# du log2012.log 

300     log2012.log

[root@localhost test]#

 illustrate:

 

Example 3: View the space occupied by the specified directory

Order:

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

 illustrate:

 

Example 4: Displaying the space occupied by multiple files

Order:

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

 illustrate:

 

Example 5: Display only the size of the sum

Order:

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

 illustrate:

 

Example 6: Display in an easy-to-read format

Order:

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

 illustrate:

 

Example 7: Both files and directories are displayed

Order:

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

 illustrate:

 

Example 8: Display the size of the disk space occupied by several files or directories, and count their sum

Order:

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

 

illustrate:

  After adding the -c option, du not only displays the size of the disk space occupied by the two directories, but also counts their sum on the last line.

 

Example 9: Sort by space size

Order:

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

 illustrate:

 

Example 10: Output the space used by each subdirectory under the current directory

Order:

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

 illustrate:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325131253&siteId=291194637