Original source: http://www.cnblogs.com/peida/archive/2012/12/07/2806483.html
The Linux du command also looks at the space used, but unlike the DF command, the Linux du command is a view of the space used by the file and directory disks , or some difference 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:
[email protected] 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.
[Email protected] test]#
Description
Displays only the directory size of subdirectories below the current directory and the total size of the current directory, with the bottom 1288 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] test]# du Log2012.log
Log2012.log
[Email protected] test]#
Description
Example 3: View the occupied space for a specified directory
Command:
Du SCF
Output:
[email protected] 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
[Ro[email protected] test]#
Description
Example 4: Show the space occupied by multiple files
Command:
Du log30.tar.gz log31.tar.gz
Output:
[email protected] test]# du log30.tar.gz log31.tar.gz
4 log30.tar.gz
4 log31.tar.gz
[Email protected] test]#
Description
Example 5: Show only the sum size
Command:
Du-s
Output:
[Email protected] test]# du-s
1288.
[Email protected] test]# du-s SCF
Scf
[Email protected] test]# CD.
[Email protected] soft]# du-s test
1288 test
[Email protected] soft]#
Description
Example 6: Easy-to-read format display
Command:
Du-h Test
Output:
[Email protected] 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
[Email protected] soft]#
Description
Example 7: Files and directories are displayed
Command:
Output:
[Email protected] 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
[Email protected] soft]#
Description
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] test]# du-c log30.tar.gz log31.tar.gz
4 log30.tar.gz
4 log31.tar.gz
8 Total
[Email protected] test]#
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] 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
[Email protected] test]#
Description
Example 10: Output the space used by each subdirectory under the current directory
Command:
Du-h--max-depth=1
Output:
[Email protected] test]# du-h--max-depth=1
608K./test6
308K./test4
32K./SCF
8.0K./test3
1.3M.
Linux commands (8) du