Skip to main content

Module 5: Disk & Storage

Lesson 45: du Command

In this lesson, you'll learn how to use the du command to check disk usage of files and directories in Linux.

The Linux du (Disk Usage) is a standard Unix/Linux command used to check the disk usage information of files and directories on a machine.

The du command has many parameter options that can be used to get the results in many formats. It also displays the files and directory sizes in a recursive manner.

Let's explain some useful du commands with examples, which will help you determine the sizes of files and directories in Linux.

du Command Syntax

# du [OPTIONS] [FILE/DIRECTORY]

du Command Options

Option Description
-h Display sizes in human-readable format (KB, MB, GB)
-s Display only the total size of a directory
-a Display disk usage of all files and directories
-k Display sizes in 1024-byte (Kilobyte) blocks
-m Count blocks in Megabyte units
-c Display a grand total at the last line
--exclude=PATTERN Exclude files matching a pattern
--time Display the last modification time alongside usage

1. Find the Size of a Directory

To obtain a summary of disk usage for a directory tree /home/ubuntu and its subdirectories, use the following command.

# du /home/ubuntu
4	/home/ubuntu/Templates
4	/home/ubuntu/Public
12	/home/ubuntu/.gnupg
4	/home/ubuntu/Videos
21504	/home/ubuntu/Documents
4	/home/ubuntu/Desktop
4	/home/ubuntu/Pictures/Screenshots
...
175840	/home/ubuntu

The output of the above command displays the number of disk blocks in the /home/ubuntu directory along with its sub-directories.

2. Find the Directory Size in Human-Readable Format

By employing the -h option with the du command, you can obtain results in a "Human Readable Format", which enables you to view sizes in units such as Bytes, Kilobytes, Megabytes, Gigabytes, and so on.

# du -h /home/ubuntu
4.0K	/home/ubuntu/Templates
4.0K	/home/ubuntu/Public
12K	/home/ubuntu/.gnupg
4.0K	/home/ubuntu/Videos
21M	/home/ubuntu/Documents
4.0K	/home/ubuntu/Desktop
184K	/home/ubuntu/Pictures/Screenshots
188K	/home/ubuntu/Pictures
...
173M	/home/ubuntu

3. Find the Total Size of a Directory

Pro TecMint Β· Root Plan
This Article is for Root Members
Join Root to read the full article and unlock everything

Full Access to Every Article, Course & Certification Track

Join thousands of Linux professionals who use Pro TecMint to advance their careers.

Ad-free access to all premium articles
All courses: Learn Linux, Bash, Golang, Ubuntu and more
RHCSA, RHCE, LFCS & LFCA certification prep
New courses added every month
Private Telegram community & priority support
Root Plan
$8/mo
or $59/year billed annually
Save $37 with annual plan
Start Reading This Article in the Next 60 Seconds
Join Root Plan β†’