Finding the largest directories quickly identifies where disk space is concentrated, enabling targeted cleanup before full filesystems cause write failures, crashes, or stalled updates.

On Linux, du walks a directory tree and totals disk usage, while --max-depth limits reporting to a summary level that keeps scans readable. Piping the results into sort with human-size sorting highlights the heaviest paths first, making it easier to decide where to drill down next.

Directory scans can be slow on large trees and the reported sizes reflect allocated disk blocks rather than the apparent size of sparse files. The --apparent-size option switches to logical sizes when needed. Running commands with sudo reduces permission gaps, and confirming the target directory size before removing data helps avoid deleting the wrong subtree.

Steps to find the largest directories with du in Linux:

  1. Summarize top-level directory sizes on the filesystem mount.
    $ sudo du -xh --max-depth=1 / 2>/dev/null | sort -hr | head -n 12
    5.7G	/
    2.8G	/usr
    833M	/var
    6.3M	/etc
    84K	/tmp
    52K	/home
    16K	/root
    16K	/lost+found
    8.0K	/snap
    8.0K	/media
    4.0K	/srv
    4.0K	/sbin.usr-is-merged

    -x keeps the scan on the same filesystem, avoiding sizes from other mounts under the target path.

  2. Summarize immediate subdirectories inside a large top-level directory.
    $ sudo du -xh --max-depth=1 /var | sort -hr | head -n 10
    833M	/var
    402M	/var/log
    278M	/var/lib
    152M	/var/cache
    2.1M	/var/backups
    52K	/var/tmp
    16K	/var/spool
    4.0K	/var/snap
    4.0K	/var/opt
    4.0K	/var/mail
  3. Drill into a heavy subtree by increasing --max-depth.
    $ sudo du -xh --max-depth=2 /var/lib | sort -hr | head -n 12
    278M	/var/lib
    229M	/var/lib/apt/lists
    229M	/var/lib/apt
    38M	/var/lib/dpkg
    36M	/var/lib/dpkg/info
    5.8M	/var/lib/ubuntu-advantage
    5.7M	/var/lib/ubuntu-advantage/apt-esm
    3.6M	/var/lib/command-not-found
    1.8M	/var/lib/fwupd/metadata
    1.8M	/var/lib/fwupd
    696K	/var/lib/systemd
    396K	/var/lib/systemd/deb-systemd-helper-enabled

    Running du on very large directory trees can take a long time and generate heavy disk I/O, which may impact busy systems.

  4. Scan home directories to spot space-heavy users or project trees.
    $ sudo du -xh --max-depth=1 /home | sort -hr | head -n 10
    52K	/home
    48K	/home/user
  5. Confirm the reported size for a candidate directory before cleanup.
    $ sudo du -shx /var/lib
    278M	/var/lib

    Replace /var/lib with the directory identified as large in the previous steps.