CloudsArk
Commands Linux

du Command Examples in Linux

Practice useful du command examples for everyday Linux administration and troubleshooting.

du Command Examples in Linux

Introduction

These examples show practical ways to use du on a Linux terminal. Each example is written so you can adapt it for administration or troubleshooting.

Example 1: Basic Usage

du -sh /var/log

This is the simplest form of the command and is a good starting point before adding options.

Example 2: Common Admin Task

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

This example reflects a common task on RHEL, Rocky Linux, AlmaLinux, or similar systems.

Example 3: Useful Option

du -ah /var/log | sort -h

This option helps narrow the result, change behavior, or handle a more realistic target.

Example 4: Real-World Scenario

sudo du -xhd1 / | sort -h

Use this pattern when the task moves beyond a single basic command.

Example 5: Verification

df -h /var

Example output:

1.4G    /var/log

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
du -ah /var/log | sort -h
sudo du -xhd1 / | sort -h
df -h /var

Summary

Good du usage means choosing the right option, keeping the target clear, and verifying the result with output you can explain.