du Command in Linux: Check Disk Usage

By 

Updated on

5 min read

Linux du command

The du command, short for “disk usage,” reports the estimated amount of disk space used by files and directories. It is useful for finding files and directories that take up large amounts of disk space.

How to Use the du command

The general syntax for the du command is as follows:

txt
du [OPTIONS]... FILE...

If the given FILE is a directory, du will summarize disk usage of each file and subdirectory in that directory. If no FILE is specified, du will report the disk usage of the current working directory .

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.

In practice, du -sh is one of the most common combinations because it shows a directory total in a human-readable format.

The -a option tells du to report the disk space usage of each file within the directory.

Terminal
du -a ~/Documents 

Usually, you would want to display only the space occupied by the given directory in a human-readable format. To do that, use the -h option.

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 the 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/

To report only the total size of the specified directory, and not for subdirectories use the -s option:

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

The -c 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

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

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

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 you would pass the output of du to the sort command to sort the directories by their size and then pipe the output to the head command which will print only the top 5 directories:

Terminal
sudo du -h /var/ | sort -rh | head -5
output
4.6G	/var/
2.9G	/var/lib
2.6G	/var/lib/snapd
1.7G	/var/lib/snapd/snaps
1.2G	/var/log/journal/af8ce1d394b844fea8c19ea5c6a9bd09

Quick Reference

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
du -h --max-depth=1 /var | sort -rh | head -10

This lists the ten largest first-level subdirectories 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