du Command in Linux: Check Disk Usage

By 

Updated on

6 min read

Linux du command

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.

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:

txt
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, du displays the disk usage of the given file or directory and each of its subdirectories in filesystem blocks.

Terminal
du ~/Documents

You can also pass multiple files and directories to the du command as arguments:

Terminal
du ~/Documents ~/Pictures ~/.zshrc

If you run du on a file or directory for which you do not have permissions, you will get something like “du: cannot read directory”. 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

By default, du reports sizes in filesystem blocks, 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:

Terminal
sudo du -h /var

We 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:

output
...
4.0K	/var/lib/apt/mirrors/partial
8.0K	/var/lib/apt/mirrors
205M	/var/lib/apt
2.9G	/var/lib/

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:

Terminal
sudo du -sh /var
output
2.9G	/var

This tells you that /var uses 2.9G in total, without listing every subdirectory inside it.

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.

Terminal
du -a ~/Documents

Display 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.

Terminal
sudo du -csh /var/log /var/lib
output
1.2G	/var/log
2.9G	/var/lib
4.1G	total

Limit 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:

Terminal
sudo du -h --max-depth=1 /var/lib
output
...
544K	/var/lib/usbutils
4.0K	/var/lib/acpi-support
205M	/var/lib/apt
2.9G	/var/lib

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.

Terminal
sudo du -sh --apparent-size /var/lib
output
2.9G	/var/lib

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:

Terminal
sudo du -csh ~/Do*
output
102M	/home/linuxize/Documents
358M	/home/linuxize/Downloads
460M	total

Using 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:

Terminal
sudo du -sh /var/* | sort -rh | head -5
output
2.9G	/var/lib
1.2G	/var/log
205M	/var/cache
72M	/var/backups
8.0K	/var/spool

Quick Reference

For a printable quick reference, see the du cheatsheet .

CommandDescription
du fileShow disk usage of a file or directory
du -h fileHuman-readable output (K, M, G)
du -sh dirShow total size of a directory only
du -sh *Show size of every item in the current directory
du -ah dirShow size of every file and subdirectory
du -csh dir1 dir2Show sizes and a combined grand total
du -h --max-depth=1 dirLimit output to one level of subdirectories
du -sh --apparent-size fileShow apparent size rather than disk usage
du -h dir | sort -rh | head -10List the 10 largest items in a directory

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:

Terminal
sudo du -sh /var/* | sort -rh | head -10

This 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.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

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

View author page