CloudsArk
Commands Linux

What Is the du Command in Linux?

Learn what the du command does in Linux, how its syntax works, and when to use it.

What Is the du Command in Linux?

Introduction

The du command estimates file and directory disk usage. It is useful for beginners, Linux administrators, DevOps engineers, and RHCSA students because it solves practical terminal tasks.

What the Command Does

Use du to work with the specific Linux object it manages. Before changing anything, identify the target and run a read-only check when possible.

Basic Syntax

du OPTIONS PATH

The syntax includes the command, any options, and the target object.

Common Options

  • -s: summarize total only.
  • -h: show human-readable sizes.
  • --max-depth: limit directory depth.

Practical Examples

du -sh /var/log
du -h --max-depth=1 /var
du -ah /var/log | sort -h
sudo du -xhd1 / | sort -h

Verification command:

df -h /var

Example output:

1.4G    /var/log

When to Use This Command

Use du when you need to find which directories or files are consuming space inside a filesystem. It complements df during disk-full troubleshooting.

Common Mistakes

  • Running du across huge trees without limiting depth.
  • Comparing du and df without considering deleted open files.
  • Forgetting -x when you want to stay on one filesystem.

Quick Reference

du -sh /var/log
du -h --max-depth=1 /var
df -h /var

Summary

The du command is safest when you understand the target, choose the right option, and verify the result with a separate command.