Home > File & Directory Management > du

du: Check Disk Usage

The du command reports the disk space usage of files and directories. It is particularly useful with the -sh option to check the total size of a specific directory in a human-readable format, and is essential for diagnosing disk space issues.

Overview

du (disk usage) summarizes the disk space used by specified files or directories. By default, it outputs in block units, but can be converted to a human-readable format using the -h option. It is commonly used to quickly grasp the total usage of a specific directory.

Key Features

  • Reports disk usage of files and directories
  • Calculates total usage including subdirectories
  • Supports various output formats (block, K/M/G units)
  • Used for diagnosing disk space problems

Key Options

The du command allows control over output format and calculation methods through various options.

Display and Summary

Scope and Filtering

Generated command:

Try combining the commands.

Description:

`du` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Various usage examples of the du command.

Check Total Usage of Current Directory

du -sh .

Displays the total disk usage of the current directory in a human-readable summarized format.

Check Usage of a Specific Directory

du -sh /var/log

Displays the total disk usage of the specified directory (/var/log) in a human-readable summarized format.

Usage per Subdirectory (1 Level Deep)

du -h --max-depth=1 /home

Displays the usage of each subdirectory (1 level deep) within the specified directory (/home) in a human-readable format.

Usage of All Files and Directories

du -ah /etc

Displays the usage of all files and directories within the specified directory (/etc) in a human-readable format.

Usage per Item in Current Directory

du -sh *

Displays the summarized total usage for each file and directory within the current directory.

Tips & Considerations

Tips and points to consider for effective use of the du command.

Difference between du and df

Both du and df relate to disk usage, but they measure different things.

  • du measures the actual disk space used by files and directories (the space occupied by files within the file system).
  • df reports the remaining space on the entire file system (available space relative to the total capacity of the file system).
  • The results of the two commands may differ due to factors like deleted but still open files (where inodes remain but data blocks are not yet freed) or reserved space on the file system (allocated for root user, etc.).

Performance Considerations

When running du on very large directories or file systems, consider the following:

  • Running du on a large number of files or in a deep directory structure can take a significant amount of time to complete.
  • Executing du on remotely mounted file systems (NFS, SMB, etc.) may lead to performance degradation due to network latency.

Same category commands