Unlike df, du is a view of using disk space for files and directories.
1. Command format
du [Options] [Files]
2. Command Function
Display disk usage space for files or directories.
3. Command parameters
- a or - all, showing the size of all files and directories, default output unit is byte.
- b, - bytes, in which byte is the output unit when displaying the directory or file size.
- c, - total, which shows the total of all directories or files, will appear "xxx total" at the end of the output.
- k, - kilobytes, the unit of output is KB (1024 bytes).
- m or --- megabytes, the output unit is MB.
- s, - summary, lists only the sum of all files and directories.
- h, - human-readable, with K, M, G as output units, improves the readability of information.
- x, - one-file-xystem, which is based on the file system being processed at the beginning, is skipped in case of other different file system directories.
- L, < Symbolic Link > or --- dereference < Symbolic Link >, the size of the source file for the symbolic link is specified in the display option.
- S, - separate-dirs, shows the size of the directory, and does not contain its subdirectories.
Exclude = directory or file >, skipping the specified directory or file.
- D or --- dereference-args, which displays the size of the source file for the specified symbolic link.
- H, - si, and - H parameters are the same, but K, M, G are converted into 1000 units.
- Or --- count-links, which repeatedly calculates the files linked to the hardware.
4. Use examples
Example 1: Space occupied by displaying directories or files
Command: du
# 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 .
Description: Display the size of the current directory and its subdirectories, the bottom 1288 is the size of the current directory.
Example 2: Display the space occupied by the specified file
Command: du log2012.log
# du log2012.log
300 log2012.log
Example 3: View the space occupied by the specified directory
Command: du scf
# 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
Example 4: Display space occupied by multiple files
Command: du log30.tar.gz log31.tar.gz
# du log30.tar.gz log31.tar.gz
4 log30.tar.gz
4 log31.tar.gz
Example 5: Show only the sum size
Command: du-s
# du -s
1288 .
# du -s scf
32 scf
# cd ..
# du -s test
1288 test
Example 6: Easy-to-read format display
Command: du-h test
# 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
Example 7: Both files and directories are displayed
# 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
Example 8: Display the size of disk space occupied by several files or directories, and also count their total.
Command: du-c log30.tar.gz log31.tar.gz
# du -c log30.tar.gz log31.tar.gz
4 log30.tar.gz
4 log31.tar.gz
8 Total
Note: With the - c option, du not only displays the disk space occupied by the directories, but also counts the total in the last line.
Example 9: Sort by space size
Command: Du | sort - NR | more
# 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
Example 10: In the current directory, output the disk space used by each subdirectory
Command: du-h -- MAX-depth = 1
# du -h --max-depth=1
608K ./test6
308K ./test4
32K ./scf
8.0K ./test3
1.3M .