Want the size of a directory right now? Run this:
du -sh /path/to/directory
The -s flag summarizes (one total instead of every subfolder), and -h makes the output human-readable โ so you get 2.4G instead of 2516582 blocks. That's it. That's the command 90% of people are looking for.
Everything below is the stuff you'll actually need the second time you check: subfolder sizes, finding what's eating your disk, excluding junk directories, and why du and df sometimes disagree. Managing disk space is essential for system administrators and everyday Linux users. Knowing how to check the size of a directory in Linux allows you to identify large folders, clean up unnecessary files, and optimize storage.

๐ Understanding Directory Sizes in Linux
Linux does not display directory sizes directly because directories function as containers for files rather than storing data themselves. Instead, Linux calculates a directory's size based on the total size of all files within it, including subdirectories.
Using commands like du, ls, and find, users can analyze directory sizes efficiently. The du command provides a complete breakdown of disk usage, while ls helps check individual file sizes. If you're new to Linux, check out our guide on basic Linux commands to improve your command-line skills.
๐ What Command Shows Directory Size in Linux?
Four tools get thrown around here, and they don't do the same job. Mixing them up is the #1 reason people get confused numbers.
| Command | What it actually measures | Example | Shows folder total? | Shows subfolders? |
du |
Disk usage of files and directories | du -sh /home |
Yes | Yes |
ls |
File listing and individual file sizes | ls -lh |
No | No |
df |
Free/used space per filesystem | df -h |
No | No |
find |
Filters files before you measure them | find . -name "*.log" |
No (pipe it to du) |
N/A |
Use du for total directory size
du stands for disk usage. It walks the tree and adds up the blocks each file occupies. This is the only one of the four that gives you a true folder total.
Use ls for file sizes, not folder totals
Run ls -lh on a directory and you'll see something like 4.0K next to it. That's not the contents โ it's the size of the directory inode, the little index the filesystem uses to track entries. Beginners get burned by this constantly. For a deeper walkthrough of listing files and interpreting output, read our guide on the ls command in Linux.
Use df for filesystem space
df -h tells you how full a mount point is. Useful when a server throws "No space left on device," but it won't tell you which folder is guilty.
Use find to measure specific file types
Need the combined size of every .log file under a path? Chain it: find /var -name "*.log" -exec du -ch {} + | tail -1. Handy for log cleanup audits. If you want to identify old files before deleting them, our guide on how to check file creation time in Linux shows you how to see which files have been around the longest.

๐ How to Check the Size of a Directory in Linux with du
This is the section worth bookmarking. Every example below was tested on Ubuntu 22.04 and AlmaLinux 9.
Check the total size of a folder
du -sh /var/www
One line, one number. Works from anywhere โ you don't need to cd into the folder first. The -s flag shows only the total size of the directory, and -h displays sizes in KB, MB, or GB instead of bytes.
Check the size of subdirectories
du -h --max-depth=1 /var/www
--max-depth=1 stops the recursion one level down, so you see each immediate subfolder plus a grand total. This is the go-to when hunting for bloat. Go to depth 2 if the first pass isn't specific enough.
List files and folders recursively
du -ah /var/www
The -a flag includes individual files, not just directories. On a big tree this dumps thousands of lines, so pipe it somewhere useful.
Show output in MB or GB
-h picks the unit automatically. If you need a fixed unit โ say, for a script that compares numbers โ force it:
du -BG /path/to/directory
du -sm /path/to/directory
-BG reports in gigabytes, -sm in megabytes. Note that -BG rounds up, so a 200 MB folder shows as 1G. Don't panic.
Stay on one filesystem with du -x
du -x /
If you've got extra volumes, NFS shares, or bind mounts hanging off a path, -x keeps du from wandering into them. On a VPS with attached block storage this saves you from wildly inflated totals โ and from a scan that takes fifteen minutes.
Exclude folders or file patterns
du -h --max-depth=1 --exclude=node_modules /path/to/project
du -sh --exclude="*.log" /var/www
Anyone auditing a dev server knows why node_modules gets its own exclusion. You can stack multiple --exclude flags.
When you need sudo
Scanning system paths as a normal user will spray "Permission denied" at you. Prefix with sudo:
sudo du -sh /var/log

๐ How to Find the Largest Directories in Linux
Your disk hits 100%. Support ticket comes in. This is the workflow.
Sort folders by size
du -h --max-depth=1 /var | sort -hr
sort -hr sorts human-readable numbers in reverse, so the biggest offender lands at the top. Then repeat one level deeper into whatever won.
Show the top 10 largest directories
du -h --max-depth=2 / | sort -hr | head -10
Find the largest files and folders together
du -ah /var | sort -hr | head -20
Nine times out of ten it's /var/log, a runaway MySQL binlog, or an old backup someone forgot about. The culprit is almost never a mystery once you sort the output โ people just skip the sort and squint at raw dumps instead.
๐ How to Check Disk Usage by Folder in Linux
Current directory and everything in it
du -sh .
du -sh *
du -sh * uses shell globbing, which means hidden dotfiles get skipped. To include them:
du -sh .[!.]* *
Worth knowing: du -sh . or du -sh /path does include hidden contents automatically. It's only the wildcard form that misses them.
Specific paths worth checking on any server
/var/logโ rotated logs that never got cleaned/homeโ user data, per-account with--max-depth=1/tmpโ stale uploads and session files/var/wwwโ site assets, cache folders, old releases/backupโ the classic silent disk killer
When to use df -h instead
Use df -h first to confirm which filesystem is full, then use du to find out why. That order saves time. If your disk is full and you need to act fast, our Linux server troubleshooting guide covers common recovery steps.
๐ง Checking Directory Size Across Distros
du, df, ls, and find ship with coreutils on every mainstream distro โ Ubuntu, Debian, CentOS, AlmaLinux, Rocky Linux, they all behave the same. No install needed. The only difference is package managers when you want extra tools:
sudo apt install ncdu baobab # Ubuntu / Debian
sudo dnf install ncdu # AlmaLinux / Rocky / Fedora
sudo yum install ncdu # older CentOS 7
One caveat: BusyBox-based systems (Alpine containers) have a trimmed du without --max-depth. Use -d 1 there.
๐ฅ๏ธ GUI and Interactive Tools to Check Folder Size
Using ncdu in the terminal
If you spend time over SSH, install ncdu and stop typing du pipelines. It scans once, then lets you arrow-key through the tree sorted by size, and delete right from the interface with d. Massive time saver on messy servers.
ncdu /var

Using Disk Usage Analyzer (baobab)
Desktop users get baobab, GNOME's Disk Usage Analyzer. It draws a ring chart of your storage โ genuinely nice for spotting a 40 GB folder you'd never have guessed. It needs a desktop session, so it's useless on a headless VPS. Install it on Ubuntu with:
sudo apt install baobab
baobab
File manager properties
Right-click a folder in Nautilus or Dolphin, hit Properties, wait for the count. Fine for one folder. Painful for anything else.
โ ๏ธ Common Issues When Checking Folder Size in Linux
Permission denied errors
du can't read directories your user has no access to, and it silently omits them from the total โ so your number comes out too low. Use sudo, or silence the noise with du -sh /var 2>/dev/null if you know you don't need those paths.
Why totals may not match df
Three usual reasons: deleted files still held open by a running process (check with lsof +L1), reserved blocks on ext4 (roughly 5% by default), and files hidden underneath a mount point. du counts files; df counts blocks the filesystem has handed out. If you need to identify which process is holding a deleted file open, our guide on how to find which process is using a file in Linux walks through the exact steps.
When the problem is simply that the filesystem itself is too small, you may want to extend the partition size in Linux rather than endlessly deleting files.
Apparent size vs actual disk usage
du -sh /path
du -sh --apparent-size /path
The first shows blocks actually allocated on disk. The second shows the logical file size. They differ because filesystems allocate in fixed blocks (a 1-byte file still eats 4 KB), and because sparse files โ VM disk images, database files โ report far larger than they occupy. I've seen a "100 GB" qcow2 image using 6 GB of real space.
Hidden files and mounted directories
The short version: pass a path, not a wildcard, and add -x when mount points are in play.
๐ Unix Command to Check Folder Size in GB
For Unix-based systems (including macOS), the du command works similarly:
du -sh /Users/username/Documents
To ensure output in gigabytes:
du -sh --block-size=G /Users/username/Documents
๐ค Automate Directory Size Checks with a Bash Script
Manual checks are fine until you're running a dozen servers. Here's a script with input validation and a threshold alert:
#!/bin/bash
DIR="$1"
LIMIT_GB=5
if [ -z "$DIR" ]; then
echo "Usage: $0 /path/to/directory"
exit 1
fi
SIZE=$(du -sBG "$DIR" | cut -f1 | tr -d 'G')
echo "Directory: $DIR"
echo "Size: ${SIZE}GB"
if [ "$SIZE" -ge "$LIMIT_GB" ]; then
echo "Warning: Directory exceeds ${LIMIT_GB}GB"
fi
Save it as dirsize.sh, run chmod +x dirsize.sh, then schedule it. This cron entry checks /var/log every morning at 6 and appends to a log file:
0 6 * * * /usr/local/bin/dirsize.sh /var/log >> /var/log/dirsize-report.log 2>&1
Swap the echo warning for a mail or webhook call and you've got real alerting. A performance note: on trees with millions of inodes, du is I/O heavy. Limit depth, run it off-peak, and skip network mounts.
๐ฏ Conclusion
Learning how to check the size of a directory in Linux is crucial for managing disk space and maintaining system performance. Whether you need to check the total size of a directory, analyze individual files, or sort directories by size, Linux provides powerful tools to get the job done.
The du command is the most effective way to check folder sizes, while ls helps list file sizes within a directory. For advanced users, combining find with du enables filtering file types and calculating specific storage usage. If you remember one thing, remember du -sh /path for a total and du -h --max-depth=1 /path | sort -hr for the hunt. Those two cover almost every real situation. Add ncdu to your standard server toolkit and you'll spend a lot less time guessing where your disk went.
For those managing multiple files and directories, consider using Linux VPS Hosting for optimized performance and better storage management. With full root access, you can run all the commands in this guide โ from du to ncdu โ on a server built for exactly this kind of housekeeping.


Leave A Comment