Linux du Command
The Linux du (disk usage) command is used to display the sizes of directories or files.
du shows the disk space used by the specified directory or file.
Syntax
du [-abcDhHklmsSx][-L <symbolic link>][-X <file>][--block-size][--exclude=<directory or file>][--max-depth=<directory levels>][--help][--version][directory or file]
Parameter Description:
- -a or -all: Display the sizes of individual files in the directory.
- -b or -bytes: Display the sizes of directories or files in bytes.
- -c or --total: In addition to displaying the sizes of individual directories or files, also display the total sum of all directories or files.
- -D or --dereference-args: Show the size of the source file of the specified symbolic link.
- -h or --human-readable: Display sizes in units of K, M, G for better readability.
- -H or --si: Same as -h, but K, M, G are calculated in units of 1000.
- -k or --kilobytes: Display sizes in units of 1024 bytes.
- -l or --count-links: Count files linked multiple times.
- -L<symbolic link> or --dereference<symbolic link>: Show the size of the source file of the specified symbolic link.
- -m or --megabytes: Display sizes in units of 1MB.
- -s or --summarize: Show only the total size.
- -S or --separate-dirs: Display the sizes of individual directories without including the sizes of their subdirectories.
- -x or --one-file-xystem: Ignore directories on different file systems from the one initially processed.
- -X<file> or --exclude-from=<file>: Specify directories or files in the <file>.
- --exclude=<directory or file>: Skip the specified directory or file.
- --max-depth=<directory levels>: Ignore directories beyond the specified depth level.
- --help: Display help information.
- --version: Display version information.
Examples
Display the space occupied by directories or files:
# 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 .
Only show the sizes of subdirectories under the current directory and the total size of the current directory, where 1288 is the total size of the current directory.
Display the space occupied by a specified file:
# du log2012.log
300 log2012.log
Display the space usage of the test directory in a human-readable format:
# 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