Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Disk Usage with du and df | Monitoring and Diagnostics
Linux Terminal Tools

bookDisk Usage with du and df

Monitoring disk usage is a critical task for maintaining a healthy Linux system. Over time, log files, caches, and user data can accumulate, consuming valuable disk space. If you do not keep track of available space, you risk running out of storage, which can lead to failed system operations or data loss. To avoid these issues, you need reliable tools to analyze and manage disk usage effectively.

# Summarize disk usage for a directory in human-readable format
du -h /var/log

# Limit output to one level deep (top-level subdirectories)
du -h --max-depth=1 /home/username

# Show disk usage for a single file
du -h /etc/passwd

The du command displays the amount of disk space used by files and directories. When you run du -h, the -h flag makes the output human-readable by using units like K (kilobytes), M (megabytes), and G (gigabytes). The --max-depth option allows you to control how deep du traverses into subdirectories, making it easier to get a summary view at different directory levels. Each line of the du output shows the size followed by the corresponding directory or file, helping you identify which locations consume the most space.

Common du pitfalls
expand arrow
  • Running du on directories with restricted permissions might produce errors or incomplete results;
  • Hidden files and directories are included by default, which can sometimes lead to surprises in reported usage;
  • Disk usage reported by du may not match df if files are open and deleted but still held by running processes.
Interpreting symbolic links
expand arrow
  • By default, du reports the size of the link file itself, not the target;
  • Use the -L option to follow symlinks and report the size of the target files or directories;
  • Be cautious with -L as it may result in counting the same data multiple times if symlinks point to the same location.
# Show disk space usage for all mounted filesystems in human-readable format
df -h

# Display filesystem type along with usage
df -hT

# Check usage for a specific filesystem or mount point
df -h /home

While du provides detailed information about the space used by specific files and directories, the df command offers an overview of disk space usage at the filesystem level. df -h shows the total, used, and available space for each mounted filesystem, making it easy to spot full or nearly full partitions. By combining du and df, you can first identify a full filesystem with df, then use du to drill down into which directories or files are consuming the most space. This approach helps you efficiently diagnose and resolve storage bottlenecks.

question mark

Which command would you use to check the total available space on a mounted filesystem?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 2

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Suggested prompts:

Can you explain the difference between `du` and `df` in more detail?

What are some common scenarios where I should use `du` versus `df`?

Are there any other useful options or flags for these commands?

bookDisk Usage with du and df

Veeg om het menu te tonen

Monitoring disk usage is a critical task for maintaining a healthy Linux system. Over time, log files, caches, and user data can accumulate, consuming valuable disk space. If you do not keep track of available space, you risk running out of storage, which can lead to failed system operations or data loss. To avoid these issues, you need reliable tools to analyze and manage disk usage effectively.

# Summarize disk usage for a directory in human-readable format
du -h /var/log

# Limit output to one level deep (top-level subdirectories)
du -h --max-depth=1 /home/username

# Show disk usage for a single file
du -h /etc/passwd

The du command displays the amount of disk space used by files and directories. When you run du -h, the -h flag makes the output human-readable by using units like K (kilobytes), M (megabytes), and G (gigabytes). The --max-depth option allows you to control how deep du traverses into subdirectories, making it easier to get a summary view at different directory levels. Each line of the du output shows the size followed by the corresponding directory or file, helping you identify which locations consume the most space.

Common du pitfalls
expand arrow
  • Running du on directories with restricted permissions might produce errors or incomplete results;
  • Hidden files and directories are included by default, which can sometimes lead to surprises in reported usage;
  • Disk usage reported by du may not match df if files are open and deleted but still held by running processes.
Interpreting symbolic links
expand arrow
  • By default, du reports the size of the link file itself, not the target;
  • Use the -L option to follow symlinks and report the size of the target files or directories;
  • Be cautious with -L as it may result in counting the same data multiple times if symlinks point to the same location.
# Show disk space usage for all mounted filesystems in human-readable format
df -h

# Display filesystem type along with usage
df -hT

# Check usage for a specific filesystem or mount point
df -h /home

While du provides detailed information about the space used by specific files and directories, the df command offers an overview of disk space usage at the filesystem level. df -h shows the total, used, and available space for each mounted filesystem, making it easy to spot full or nearly full partitions. By combining du and df, you can first identify a full filesystem with df, then use du to drill down into which directories or files are consuming the most space. This approach helps you efficiently diagnose and resolve storage bottlenecks.

question mark

Which command would you use to check the total available space on a mounted filesystem?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 2
some-alt