Understanding the du Command

Basic Usage of du

The du (Disk Usage) command is used to estimate file space usage of directories and their contents. It provides a summary of the disk usage for each specified directory, displaying the amount of space used by files and subdirectories.

du [OPTION]... [DIRECTORY]...

Options Available with du

-h (Human-readable)

Display sizes in human-readable format (e.g., KB, MB, GB):

du -h

-s (Summary)

Display only the total size for each specified directory, without listing sizes of subdirectories:

du -s

-a (All files)

Include files in the output, not just directories:

du -a

-c (Total)

Display a grand total for all arguments after displaying their individual sizes:

du -c

-d N (Depth)

Limit the output to a specified depth of directories:

du -d N

--max-depth=N

Similar to -d, limit the output to a maximum depth of N directories:

du --max-depth=N

--help

Display help information for the command:

du --help

--version

Display the version information of the command:

du --version

Examples of du Command

Display Disk Usage of Current Directory

du

This command displays the disk usage of all files and directories in the current directory.

Display Human-readable Output

du -h

This command shows the disk usage in a more readable format with units (KB, MB, GB).

Display Summary for a Directory

du -sh /path/to/directory

This command displays the total disk usage for the specified directory.

Understanding Disk Usage Information

The output of the du command typically includes the following columns:

Summary of Options

Option Description
-h Display sizes in human-readable format.
-s Display only the total size for each specified directory.
-a Include files in the output.
-c Display a grand total for all arguments.
-d N Limit the output to a specified depth of directories.
--max-depth=N Limit the output to a maximum depth of N directories.
--help Display help information for the command.
--version Display the version information of the command.