du Command in Linux: Check Disk Usage with du -sh

When a disk fills up, the first question is always the same: what is taking up all the space? The du command, short for “disk usage,” answers that question. It reports the estimated amount of disk space used by files and directories, so you can track down the largest offenders and free up room.
Most of the time, you will run it as du -sh followed by a directory path. That prints the total size of the directory on a single line, in units such as M and G.
This guide explains how to use the du command, covers its most common options such as -s and -h, and shows practical examples for checking disk usage on a Linux system.
du Command Syntax
The general syntax for the du command is as follows:
du [OPTION]... [FILE]...If the given FILE is a directory, du will report disk usage for that directory and its subdirectories. If no FILE is specified, du will report the disk usage of the current working directory
.
How to Use the du Command
When executed without any option, GNU du normally displays the disk usage of the given file or directory and each of its subdirectories in 1 KiB units.
du ~/DocumentsYou can also pass multiple files and directories to the du command as arguments:
du ~/Documents ~/Pictures ~/.zshrcIf you run du on a file or directory for which you do not have permissions, you will get an error such as du: cannot read directory '/root': Permission denied. In this situation, you will need to prepend the command with sudo
.
du has many options. The following sections cover the most frequently used ones.
Display Disk Usage in Human-Readable Format
GNU du normally reports sizes in 1 KiB units (1,024 bytes), which are hard to read at a glance. The -h (--human-readable) option prints sizes in units such as K, M, and G.
For example, to get the size of /var and all of its subdirectories in a human-readable format, run:
sudo du -h /varWe are using sudo because most of the files and directories inside the /var directory are owned by the root user and are not readable by regular users. The output will look something like this:
...
24M /var/cache/fwupd
1.2G /var/cache
8.0K /var/crash
4.0K /var/local
2.9G /varThe last line is the total size of /var, including everything below it.
Show the Total Size of a Directory
By default, du prints a line for every subdirectory. To report only the total size of the specified directory, and not each subdirectory, use the -s (--summarize) option. Combined with -h, the du -sh command is one of the most common ways to check how much space a directory uses:
sudo du -sh /var2.9G /varThis tells you that /var uses 2.9G in total, without listing every subdirectory inside it.
To get the total size of each file and directory in the current directory, use the * wildcard:
du -sh *The shell expands * before du runs, and the expansion skips hidden files and directories (names starting with a dot). In a home directory, those are often the largest items, such as .cache and .local. To include hidden items, pass the current directory itself and limit the output depth:
du -ah --max-depth=1 .The -a option includes files in the output, and --max-depth=1 limits the listing to immediate entries. This includes hidden names such as .cache and ..backup, and it works even when there are no hidden files. The last line shows the total for the current directory (.).
Show the Size of Every File
The -a (--all) option tells du to report the disk space usage of each file within the directory, not only the directories.
du -a ~/DocumentsDisplay a Grand Total
The -c (--total) option tells du to report a grand total. This is useful when you want to get the combined size of two or more directories.
sudo du -csh /var/lib /var/cache1.7G /var/lib
1.2G /var/cache
2.9G totalLimit the Directory Depth
If you want to display the disk usage of n-level subdirectories, use the --max-depth option and specify the subdirectory level. For example, to get a report about the first-level directories you would use:
sudo du -h --max-depth=1 /var/lib...
1.2G /var/lib/snapd
4.0K /var/lib/python
4.0K /var/lib/upower
4.0K /var/lib/os-prober
2.0M /var/lib/fwupd
8.0K /var/lib/logrotate
1.7G /var/libEach first-level subdirectory gets its own line, and the total for /var/lib comes last. The lines are not sorted by size.
You can shorten --max-depth=1 to -d 1:
sudo du -h -d 1 /var/libThe short form also works with the BSD du on macOS. The macOS version does not accept --max-depth.
Stay on One Filesystem
When you run du on /, it also walks into /proc, /run, /tmp, and every other filesystem mounted below the root. Those mounts add permission errors and inflate the total. The -x (--one-file-system) option tells du to skip directories that are on a different filesystem.
To see which top-level directories use the most space on the root filesystem, run:
sudo du -xh -d 1 / | sort -rh | head -57.2G /
4.4G /usr
2.9G /var
15M /home
13M /etcThe first line is the total for the root filesystem. Without -x, the same command reports 11G on this system. The difference comes from the snap packages mounted under /snap, the separate /boot partition, and the in-memory /tmp.
Once you know which directory is the largest, run the same command on it to go one level deeper.
Show the Apparent Size
The default behavior of the du utility is to report the disk space used by the directory or file. To find the apparent size of a file, use the --apparent-size switch. The “apparent size” of a file is how much data is actually in the file.
du -sh --apparent-size /usr/share/doc50M /usr/share/docWithout the option, du -sh /usr/share/doc reports 73M for the same directory. The directory holds thousands of small files, and the filesystem rounds each one up to a whole number of 4K blocks.
Use Shell Patterns with du
du also allows you to use shell patterns. For example, to get the size of all directories starting with “Do” in your home directory you would run:
du -csh ~/Do*102M /home/linuxize/Documents
358M /home/linuxize/Downloads
460M totalUsing du with Other Commands
The du command can be combined with other commands using pipes.
For example, to print the 5 largest directories
inside the /var directory, pass the output of du to the sort command to sort the directories by their size. Then pipe the output to the head
command, which prints only the top 5 entries:
sudo du -sh /var/* | sort -rh | head -51.7G /var/lib
1.2G /var/cache
29M /var/log
2.2M /var/backups
104K /var/snapQuick Reference
For a printable quick reference, see the du cheatsheet .
| Command | Description |
|---|---|
du file | Show disk usage of a file or directory |
du -h file | Human-readable output (K, M, G) |
du -sh dir | Show total size of a directory only |
du -sh * | Show size of every item in the current directory |
du -ah --max-depth=1 . | Include hidden items and show the current-directory total |
du -ah dir | Show size of every file and subdirectory |
du -csh dir1 dir2 | Show sizes and a combined grand total |
du -h --max-depth=1 dir | Limit output to one level of subdirectories |
du -h -d 1 dir | Short form of --max-depth=1 |
sudo du -xh -d 1 / | Show top-level directories on the root filesystem only |
du -sh --apparent-size file | Show apparent size rather than disk usage |
du -h dir | sort -rh | head -10 | List the 10 largest directories in the tree |
FAQ
What is the difference between du and df?du reports the space used by specific files and directories. df
reports the total, used, and available space on mounted filesystems. Use du to find what is consuming space, and df to check how much space is left on a disk.
What is the difference between disk usage and apparent size?
Disk usage (du default) reflects the actual space allocated on disk, which is rounded up to the filesystem block size. Apparent size (--apparent-size) is the exact byte count of the file’s data. For small files, disk usage is often larger than the apparent size.
Why does du show different results than the file manager?
File managers typically report apparent size. du reports allocated disk blocks. Sparse files, filesystem block size, and hard links can also cause differences between the two values.
Why do many examples use sudo du?
Some directories, such as parts of /var or /root, are not readable by regular users. Running du with sudo avoids permission errors and produces a more complete size report.
How do I find the largest directories under a path?
Combine du with sort and head:
sudo du -sh /var/* | sort -rh | head -10This lists the ten largest items directly under /var in descending order.
Conclusion
The du command is the standard tool for finding which files and directories are consuming disk space on a Linux system. Unlike df
, which reports filesystem-level totals, du lets you drill down into specific directories to locate large files and directories.
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