The Linux du command also looks at the use of space, but unlike the DF command, the Linux du command is to see whether the currently specified file or directory (recursively displaying subdirectories) consumes disk space or is somewhat different from the DF command.
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 output in kilobytes (1024bytes).
-M or--megabytes is output in megabytes.
-S or--summarize displays only the totals, listing only the last added total value.
-H or--human-readable in k,m,g to improve the readability of the information.
-X or--one-file-xystem the file system at the beginning of the processing, if any other different file system directories are skipped.
-l< the source file size of the symbolic link specified in the Symbolic link > or--dereference< symbolic link > Display option.
-S or--separate-dirs displays the size of individual directories without the size of their subdirectories.
-x< file > or--exclude-from=< file > in < file > specify directory or file.
--exclude=< directory or File > skip the specified directory or file.
-D or--dereference-args displays the source file size for the specified symbolic link.
-H or--si is the same as the-h parameter, but the k,m,g is converted to 1000 units.
-L or--count-links duplicates the hardware-linked files.
4. Usage examples:
Example 1: display the directory or the space occupied by the file
Command: Du
Output:
-./XML -./Mem8./Thread188./glog/glog-0.3.3/src/Glog +./glog/glog-0.3.3/src/Base the./glog/glog-0.3.3/src/windows/Glog124./glog/glog-0.3.3/src/Windows780./glog/glog-0.3.3/src8./glog/glog-0.3.3/vsprojects/logging_unittest8./glog/glog-0.3.3/vsprojects/logging_unittest_static A./glog/glog-0.3.3/vsprojects/libglog_static A./glog/glog-0.3.3/vsprojects/Libglog -./glog/glog-0.3.3/vsprojects376./glog/glog-0.3.3/M4248./glog/glog-0.3.3/. Deps +./glog/glog-0.3.3/Doc7180./glog/glog-0.3.3/. Libs8./glog/glog-0.3.3/packages/rpm -./glog/glog-0.3.3/packages/Deb the./glog/glog-0.3.3/Packages17828./glog/glog-0.3.317836./Glog -./sort
43687
Description
Displays only the directory size of subdirectories below the current directory and the total size of the current directory, with the bottom 43687 being the total size of the current directory
Example 2: Display the space occupied by the specified file
Command: Du Log2012.log
Output:
[Email protected]:/home/work/test# du a.out [email protected]:
Example 3: View the occupied space for a specified directory
Command: Du SCF
Output:
[Email protected]:/home/work/test# du gdb gdb[email protected]:
Example 4: Show the space occupied by multiple files
Command: Du log30.tar.gz log31.tar.gz
Output:
[Email protected]:/home/work/test# du a. Out 4 Main.cpp[email protected]:
Example 5: Show only the sum size
Command: Du-s
Output:
[Email protected]:/home/work/test# du-s383124 . [ Email protected]:/home/work/test# du-s Redis39784 redis[email protected]:
Example 6: Easy-to-read format display
Command: Du-h test
Output:
[Email protected]:/home/work/test# du-H log16k log/boost_log/log6.8M log/ Boost_log1.1M log/logouts/test1.1M log/logouts7.9M log[email protected]:
Example 7: Files and directories are displayed
Command: Du-ah Log
Output:
[Email protected]:/home/work/test# du-AH log4.0K log/main.cpp4.0K log/log.h12k Log/boost_log/log/sign_2016- .-21_20. the. log16k Log/boost_log/Log4.0K log/boost_log/main.cpp8.0K log/boost_log/mainex.cc2.5Mlog/boost_log/a. out3.9Mlog/boost_log/LOGGER.O4.0K log/boost_log/logger.h448k Log/boost_log/MAIN.O4.0K log/boost_log/Makefile4.0K log/boost_log/Logger.cpp6.8Mlog/Boost_log8.0K log/Log.cpp4.0K log/logouts/test/X.txt1.1Mlog/logouts/test/20160614. Log1.1Mlog/logouts/Test1.1Mlog/logouts7.9MLog[email protected]:/home/work/test#
Example 8: Show how many files or directories each occupy the size of disk space, and also count their sums
Command: Du-c log30.tar.gz log31.tar.gz
Output:
[Email protected]:/home/work/test# du-7316 MD5 log/boost_log/ Log6928 log/boost_log1116 log/logouts/test1120 log/logouts8068 log15384 total[email Protected]:
Description
With the-C option, Du shows not only the size of the two directories that occupy disk space, but also the sum of them in the last line.
Example 9: Sort by Space size
Command: Du|sort-nr|more
Output:
[Email protected]:/home/work/test/log# du |sort-nr| More 8068 . 6928 . /boost_log1120 ./logouts1116 ./logouts/Test16 ./boost_log/log[email protected]:
Example 10: Output the space used by each subdirectory under the current directory
Command: Du-h--max-depth=1
Output:
[email protected]:/home/work/test# du-h--max-depth=1 7.9m ./log44k. /xml60k. /mem 8 . 0K./ thread18m. /glog60k. /sort296m. /python39m. /redis80k. /gdb44k. /minmaxheap async md528k. /move375m. [email protected]: /home/work/test#
One Linux command per day (3): Du command