All rights reserved, please indicate the source when citing
The du command in Linux is used to estimate and display the disk space used by files and directories. The name du stands for "disk usage." It is a handy utility to check how much space different files and directories are occupying on your storage devices. The basic syntax of the du command is:
du [OPTIONS] [FILES/DIRECTORIES] .
Here, "OPTIONS" are optional flags that modify the behavior of the du command, and "FILES/DIRECTORIES" are the names of the files or directories you want to analyze. If you don't specify any files or directories, the du command will display disk usage for the current directory.
Some common options for the du command include:
- -h or --human-readable: Display sizes in a human-readable format (e.g., KB, MB, GB).
- -s or --summarize: Display only the total size of the specified directories, without listing individual file sizes.
- -c or --total: Display a grand total of the disk usage at the end of the output.
- -d N or --max-depth=N: Limit the depth of the directory traversal to N levels.
- -k or --kilobytes: Display sizes in kilobytes (default unit).
- -m or --megabytes: Display sizes in megabytes.
- -g or --gigabytes: Display sizes in gigabytes.
- -B <block_size>: Set a specific block size for displaying sizes.
Here are a few examples of using the du command:
$ du -h ←Display disk usage of the current directory in human-readable format
$ du -s /path/to/directory ←Display disk usage of the current directory in human-readable format
$ du -h -d 2 /path/to/directory ←Display disk usage of files and directories within a specified depth level
$ du -c -h /path/to/directory1 /path/to/directory2 ←Display total disk usage with a grand total at the end |
The du command is useful for monitoring disk space usage, identifying space-consuming files and directories, and managing storage resources efficiently.
For more information on du operations and examples, please refer to the provided link.