Linux Folder Size: How to Check File and Directory Sizes

When a server is running low on disk space, one of the first checks is which folder is actually using the storage. The usual command for that job is du -sh /path, which prints the total disk usage for the path in a human-readable format. On Linux, “folder” and “directory” mean the same thing, so the commands below apply either way.
If you run ls -l
, directories often appear as 4096 bytes, but that value only represents directory metadata, not the size of the files below it. The du
(disk usage) command shows the real space used by files and directories. This guide explains how to use du and related commands to check sizes, find large directories, and manage disk space. It also shows how to check folder sizes in the Ubuntu desktop without a terminal.
Checking Directory Size with du
To display the total size of a directory in a human-readable format, use du with the -s (summarize) and -h (human-readable) options:
sudo du -sh /var2.0G /var-s- Display only the total size, not each subdirectory-h- Print sizes in human-readable format (K, M, G)
The command uses sudo
because many files inside /var are owned by root. Without sudo, du prints “cannot read directory” warnings for paths it cannot access.
Getting the Size of a File
To check the size of a single file, pass the file path to du:
du -sh /var/log/syslog1.7M /var/log/syslogYou can also use ls -lh to see the file size alongside other metadata:
ls -lh /var/log/syslog-rw-r----- 1 syslog adm 1.7M Nov 3 01:44 /var/log/syslogFor detailed file information including exact byte count, block size, and inode number, use stat:
stat /var/log/syslogWhen you want the byte count on its own, pass a format string to stat with the -c option:
stat -c %s /var/log/syslog1763812Listing Subdirectory Sizes
To see how much space each first-level subdirectory uses, use the --max-depth option:
sudo du -h --max-depth=1 /var4.0K /var/opt
44K /var/spool
104K /var/snap
4.0K /var/mail
2.1M /var/backups
1.5G /var/lib
4.0K /var/metrics
30M /var/log
80K /var/tmp
506M /var/cache
8.0K /var/crash
4.0K /var/local
2.0G /varEntries appear in the order du walks the directory, not by size, and the total for /var itself comes last. To rank the subdirectories instead, pipe the output through sort:
sudo du -h --max-depth=1 /var | sort -rhThe --max-depth option also has a short form, so du -h -d 1 /var does the same thing and is what you need on macOS and BSD, where the long form is not available.
You can also use the asterisk wildcard with the -c option to include a grand total:
sudo du -shc /var/*2.1M /var/backups
506M /var/cache
8.0K /var/crash
1.5G /var/lib
4.0K /var/local
0 /var/lock
30M /var/log
4.0K /var/mail
4.0K /var/metrics
4.0K /var/opt
0 /var/run
104K /var/snap
44K /var/spool
80K /var/tmp
2.0G totalThe -c flag adds the total line at the end of the output. The shell sorts the expanded names alphabetically, so the entries are easier to scan than the --max-depth output. The /var/lock and /var/run entries show 0 because they are symbolic links to /run/lock and /run, and du does not follow them. The wildcard also skips hidden files and directories (those starting with .).
To increase the depth and see two levels of subdirectories:
sudo du -h --max-depth=2 /varShowing the Size of Every Folder in the Current Directory
When you are already inside a directory, such as your home folder, you do not need to type its path. Pass the */ pattern to du instead. The trailing slash tells the shell to expand only directories:
du -sh */4.0K Desktop/
4.0K Documents/
4.0K Downloads/
4.0K Music/
63M Pictures/
4.0K Public/
4.0K Templates/
4.0K Videos/Each line shows one folder and its total size. Use du -sh * instead when you want regular files listed next to the folders. If a name in the directory starts with a dash, write the pattern as du -sh -- */ so du does not read that name as an option.
The */ pattern also matches symbolic links to directories. Because of the trailing slash, du measures their targets, which may be outside the current directory.
The pattern skips hidden folders. In a home directory, hidden folders such as .cache and .local are often among the largest items, so the output above can leave out a large part of the used space. To include them without following directory symlinks, run du on the current directory and limit the depth to one level:
du -h --max-depth=1 | sort -h4.0K ./Desktop
4.0K ./Documents
4.0K ./Downloads
4.0K ./Music
4.0K ./Public
4.0K ./Templates
4.0K ./Videos
8.0K ./.ssh
84K ./.config
552K ./.local
18M ./.cache
63M ./Pictures
81M .This time, the hidden .cache folder shows up with 18M, second only to Pictures. The last line is the total for the current directory (.). The sort -h command sorts in ascending order, which keeps the largest folders at the bottom, right above your prompt. To list files as well as folders, add the -a option, as shown in the du command guide
.
Finding the Largest Directories
To find the directories consuming the most space, pipe the output of du to sort and head:
sudo du -h /var/ | sort -rh | head -102.0G /var/
1.5G /var/lib
1.2G /var/lib/snapd/snaps
1.2G /var/lib/snapd
506M /var/cache
453M /var/cache/apt
349M /var/cache/apt/archives
150M /var/lib/apt/lists
150M /var/lib/apt
55M /var/lib/dpkgThe sort -rh command sorts in reverse order by human-readable size, placing the largest entries first. The head
command limits the output to the top 10 results.
A parent directory is always at least as large as any directory below it, so nested paths appear in pairs. In this example, almost all of /var/lib/snapd is the snaps subdirectory, where snapd keeps the downloaded snap packages.
To include individual files in the output, add the -a flag:
sudo du -ah /var/ | sort -rh | head -10Repeating du and sort gets tedious once you start drilling down folder by folder. The ncdu (NCurses Disk Usage) tool scans a path and lets you browse the results interactively, sorted by disk usage by default. Install it with sudo apt install ncdu on Ubuntu and Debian, or sudo dnf install ncdu on Fedora. On RHEL, enable the EPEL repository before installing the package. Run ncdu /var and walk into the largest folders with the arrow keys.
Excluding Directories
To skip files or directories that match a pattern, use the --exclude option. The following command leaves out every file whose name ends in .log:
sudo du -sh --exclude='*.log' /varYou can exclude multiple patterns by repeating the option:
sudo du -sh --exclude='cache' --exclude='tmp' /var1.5G /varThe total drops from 2.0G to 1.5G. Each pattern is matched against file and directory names at any depth, so --exclude='cache' skips /var/cache and also any other directory named cache below /var. Quote the patterns so the shell does not expand them before du sees them.
This is useful when you want to measure disk usage without counting log files, caches, or temporary directories.
Apparent Size vs Disk Usage
By default, du reports the disk space allocated to a file, which depends on the filesystem block size. A 1-byte file on a 4K-block filesystem still occupies 4 KB of disk space.
The --apparent-size option shows the actual amount of data in the file instead:
sudo du -sh --apparent-size /varThe apparent size is the number of bytes the file contains. The disk usage is the space the filesystem allocates. The two can differ significantly for directories with many small files.
When planning a transfer, apparent size is closer to the amount of file data than allocated disk usage, but it is not an exact measure of network traffic. rsync
can send only changed data and compress it, while scp
and sftp
add protocol overhead. Filesystem differences can also make du report different allocated sizes on the source and destination.
Checking Folder Size in the Ubuntu Desktop
On Ubuntu Desktop, you can check the size of a folder without opening a terminal. In the Files app, right-click the folder and select Properties, or select it and press Ctrl+I. The dialog counts the items inside the folder and shows their total size:

The total in this dialog does not always match du -sh. For the same folder, du -sh ~/Pictures reports 63M. Files adds up the apparent size of each file and shows the result in decimal units, where 1 MB is 1,000,000 bytes. The du -h command reports allocated disk space in binary units, where 1M is 1,048,576 bytes. To get a figure you can compare with the dialog, run du -sh --si --apparent-size ~/Pictures, which prints 66M.
To see which folders take up the most space, open Disk Usage Analyzer, which is installed by default on Ubuntu Desktop. Select Home Folder or a disk on the start screen. The app scans the location and lists its folders by size next to a rings chart:

Unlike du -sh */, Disk Usage Analyzer includes hidden folders such as .cache. Click the arrow next to a folder to expand it and see what is inside.
Checking Free Disk Space with df
The du command measures how much space files and directories use. The df
command shows how much free space remains on each mounted filesystem:
df -hFilesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 35G 13G 73% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
/dev/sdb1 200G 120G 70G 63% /dataUse du when you need to know which directories are consuming space. Use df when you need to know how much space is left on a partition.
Troubleshooting
du: cannot read directory ‘/path’: Permission denied
The current user does not have read permission on the directory. Run du with sudo to access all paths.
du and ls show different sizes
The ls -l command shows a regular file’s apparent size in bytes. The du command shows allocated disk space in blocks by default. Use du -b file or stat -c %s file when you need the apparent size as an exact byte count.
du output uses blocks instead of human-readable units
Add the -h flag to display sizes in K, M, and G. Without -h, du defaults to 1 KB blocks on most systems.
du is slow on large directory trees
The du command reads every file and subdirectory. The --max-depth option limits only what du prints, not what it scans, so it does not make the command faster. Use --exclude to skip large directories you do not need to measure, or -x to stay on one filesystem so du does not descend into other mounted disks or network shares.
Quick Reference
For a printable quick reference, see the du cheatsheet .
| Command | Description |
|---|---|
du -sh /path | Total size of a directory |
du -sh file.txt | Size of a single file |
du -h --max-depth=1 /path | Size of each first-level subdirectory |
du -h --max-depth=1 /path | sort -rh | Subdirectories ranked by size |
du -shc /path/* | Subdirectory sizes with grand total |
du -sh */ | Size of each folder in the current directory |
du -h --max-depth=1 | sort -h | Folder sizes including hidden folders, sorted |
du -ah /path | sort -rh | head -10 | Top 10 largest entries |
du -sh --exclude='*.log' /path | Exclude files matching a pattern |
du -sh --apparent-size /path | Apparent size instead of disk usage |
ls -lh file.txt | File size with metadata |
stat file.txt | Detailed file information |
stat -c %s file.txt | Exact size in bytes |
df -h | Free disk space per filesystem |
FAQ
What is the difference between du and df?
The du command measures the space used by specific files and directories. The df command shows the total, used, and available space on each mounted filesystem. Use du to find what is consuming space and df to check how much space is left.
Why does du show a larger size than the sum of the files?
Filesystems allocate space in fixed-size blocks (typically 4 KB). A 1-byte file still uses one full block. Directories with many small files show a larger du total than the sum of their apparent sizes.
How do I find the largest files and directories on the system?
Use sudo du -ahx / | sort -rh | head -20 to list the 20 largest entries on the root filesystem. The output includes both files and directories. To search only for regular files, see Find Large Files in Linux
.
What does the -s flag do in du?
The -s (summarize) flag tells du to display only the total size of the specified directory, instead of listing every subdirectory individually.
Can I check directory sizes without sudo?
You can run du wherever your user can list and traverse directories. Use sudo when permission errors prevent a complete scan.
Conclusion
Use du -sh /path when you need a quick total, then move to --max-depth or sort -rh when you need to find what is taking space. For filesystem-level free space, use df -h instead.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page