How to Check Directory Size in Linux

Understanding how much disk space a directory is consuming is one of the most practical skills in Linux administration — whether you're managing a home system, a web server, or a shared environment. Linux gives you several ways to measure directory size, and the right approach depends on what you're trying to find out. 📁

The du Command: Your Primary Tool

The du (disk usage) command is the standard way to check directory size in Linux. It reads how much disk space a directory and its contents are actually using — which can differ from the sum of individual file sizes due to how filesystems allocate blocks.

Basic syntax:

du /path/to/directory 

By default, du outputs sizes in 512-byte blocks (on many systems) or 1-kilobyte blocks, which isn't very readable. The flags you add determine how useful the output is.

Most Useful du Flags

FlagWhat It Does
-hHuman-readable output (KB, MB, GB)
-sSummary — shows total for the directory only
-aShows size of every file, not just subdirectory totals
--max-depth=NLimits recursion to N levels deep
-cAdds a grand total at the end

Examples in practice:

du -sh /home/user/documents 

This gives a single, clean summary of the entire documents directory.

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

This shows the size of each immediate subdirectory inside /var/log without drilling further down.

du -ah /home/user | sort -rh | head -20 

This lists the 20 largest files and directories inside /home/user, sorted by size — a practical way to hunt down what's consuming space.

Why File Size and Disk Usage Differ

This trips up a lot of people. A file might be 4 KB in actual content, but on a filesystem with a 4096-byte block size, it still consumes one full block. Multiply that across thousands of small files and the difference becomes significant.

du reports allocated disk space — what the filesystem has actually reserved for those files. Tools like ls -lh report logical file size — the number of bytes of actual content. Neither is wrong; they're measuring different things.

Sparse files add another layer: these are files with large empty regions that the filesystem doesn't fully allocate. In those cases, du may report a size smaller than ls.

Checking Directory Size with ncdu 🔍

For more interactive exploration, ncdu (NCurses Disk Usage) is a widely used alternative. It presents a navigable, visual breakdown of directory sizes in the terminal.

ncdu /home/user 

You can move through directories, see which subdirectories are largest, and drill down — all without running multiple commands. Most Linux distributions don't include ncdu by default, but it's available in standard package repositories.

Install examples:

  • Debian/Ubuntu: sudo apt install ncdu
  • RHEL/Fedora: sudo dnf install ncdu
  • Arch: sudo pacman -S ncdu

Using ls for Quick File-Level Checks

While ls doesn't measure directory size recursively, it can be useful for a quick look at contents:

ls -lh /path/to/directory 

This shows file sizes in human-readable format, but it won't give you a total for the directory itself. The entry shown for a directory in ls -lh output is the size of the directory entry in the filesystem — not the size of its contents. This is a common source of confusion.

Checking Available Disk Space Alongside Directory Size

Often, you check directory size because you're troubleshooting a disk space issue. The df (disk free) command shows overall disk usage at the filesystem level, not the directory level:

df -h 

This shows total size, used space, available space, and mount point for each filesystem. It answers "how full is this disk?" while du answers "what is this directory consuming?"

Using du and df together gives you the full picture: where space is going and how much headroom the filesystem has.

Variables That Affect Your Approach

How you check directory size depends on several factors specific to your setup:

  • Scale of the directory — A small project folder is fine with a single du -sh. A large /var partition with millions of files may take several minutes to scan and benefits from ncdu's progressive display.
  • Filesystem type — Filesystems like Btrfs and ZFS support compression and snapshots, meaning du output may not reflect actual storage consumption in the way you'd expect from ext4 or XFS.
  • Remote/network filesystems — Running du on NFS or CIFS mounts works, but performance can be slow and results may reflect server-side allocation rather than local disk usage.
  • Permission context — Running du as a regular user won't be able to read directories owned by other users or protected system paths. Running with sudo gives a complete picture but has security implications in shared environments.
  • Bind mounts and symbolic linksdu by default follows symbolic links selectively and may or may not count bind-mounted directories depending on flags used, which can cause size totals to look unexpected.

Different Scenarios, Different Results

A developer checking the size of a /var/www web root gets a straightforward result on a local ext4 system. A sysadmin checking the same path on a production server with Btrfs snapshots might see numbers that don't match what df reports — because snapshot data shares blocks across versions.

A user running du on a home directory with hundreds of thousands of small configuration files may find the allocated size considerably larger than expected due to filesystem block overhead. Someone scanning a media directory full of large video files will see much closer alignment between logical file size and allocated disk usage.

The commands themselves are consistent — what varies is how your specific filesystem, directory structure, file types, and user permissions interact with those commands. Understanding that gap is what turns a basic du -sh into a genuinely useful diagnostic. 🖥️