How to Use the Linux du Command (With Examples)

Linux du Command

Table of Contents

Get up to 50% off now

Become a partner with CyberPanel and gain access to an incredible offer of up to 50% off on CyberPanel add-ons. Plus, as a partner, you’ll also benefit from comprehensive marketing support and a whole lot more. Join us on this journey today!

Losing your disk space is the most frustrating part when managing your Linux system. That’s where the Linux du command comes in.

Now, what the du command in Linux does is it shows how many blocks are used for files. If you specify a File parameter that is a directory, it will report on all the files inside that directory. If you don’t provide a File parameter, the du command will look at the files in the current directory.

When the File parameter points to a directory, the block count reported includes the blocks allocated for the files within that directory as well as the blocks for the directory itself.

If the du command targets a file or directory that exists within a JFS2 snapshot, it will provide information based on the state of that object at the time the snapshot was taken. This does not account for any space that would be freed up if the snapshot were deleted. Using the -a flag will report the number of blocks for each individual file. Regardless of whether you use the -a flag, any individual files specified by the File parameter will always be listed. Using the -s flag will give you the total block count for all specified files or for all files within a directory.

What is The Syntax of the Linux du Command?

The basic syntax for the du Linux command is as follows:

du [options] [directory/file]

Here,

Tech Delivered to Your Inbox!

Get exclusive access to all things tech-savvy, and be the first to receive 

the latest updates directly in your inbox.

[options] = different flags that change how the command works

[directory/file] = the specific directory or file for which you want disk usage details. If you don’t specify a directory or file, du will use the current directory by default.

Example:

du /home/mandeep/test

Output:

44 /home/mandeep/test/data<br>2012 /home/mandeep/test/system design<br>24 /home/mandeep/test/table/sample_table/tree<br>28 /home/mandeep/test/table/sample_table<br>32 /home/mandeep/test/table<br>100104 /home/mandeep/test

Commonly Used du Command Options

LINUX-DU-COMMAND-GUIDE-FOR-2025

The du command in Linux, gives you important details about the size of each file, directory, and the total disk usage on a system. But it has multiple commands that let you adjust its function and get the information you need.

Here are some frequently used options for the du command:

CommandUse
-a or –allThis option shows the disk usage for all files, including hidden ones and directories.
-h or –human-readable
This option presents the disk usage in a format that is easy to read, like kilobytes (kB), megabytes (MB), or gigabytes (GB), rather than just bytes.
-s or –summarize
This option provides the total disk usage for a specific directory or file, rather than showing the sizes of each individual file or directory.
-c or –total
This option gives the overall total of the disk usage for all specified files and directories.
-d or –max-depth=
This option sets a limit on how deep into the directory tree du will go, where indicates the maximum number of levels to show.
-x or –one-file-system
This option makes du only show the disk usage for the current file system, ignoring any mounted file systems.
-L or –dereference
This option follows symbolic links and shows the disk usage of the files or directories they point to, instead of the links themselves.
-t or –threshold=This option only shows files and directories that are larger than the specified size limit.

Practical Examples of the du Command Linux Usage

Here are some best examples to learn to master this command:

To summarize the disk space used by a directory and its subdirectories, type:

du /home/fran

This shows the number of disk blocks in the /home/fran directory and all its subdirectories.

To summarize the disk space used by a directory and its subdirectories in 1024-byte blocks, type:

Enhance Your CyerPanel Experience Today!
Discover a world of enhanced features and show your support for our ongoing development with CyberPanel add-ons. Elevate your experience today!

du -k /home/fran

This shows the number of 1024-byte disk blocks in the /home/fran directory and all its subdirectories.

To summarize the disk space used by a directory and its subdirectories in MB blocks, type:

du -m /home/fran

This shows the number of MB disk blocks rounded to the nearest second decimal in the /home/fran directory and all its subdirectories.

To summarize the disk space used by a directory and its subdirectories in GB blocks, type:

du -g /home/fran

This shows the number of GB disk blocks rounded to the nearest second decimal in the /home/fran directory and all its subdirectories.

To display the disk usage of each file, type:

du -a /home/fran

This shows the number of disk blocks in each file and subdirectory of the /home/fran directory. The number next to a directory indicates the disk usage of that directory tree, while the number next to a regular file indicates the disk usage of that file alone.

To display only the total disk usage of a directory tree, type:

du -s /home/fran

The –s option tells the du command to show only the total disk usage of the /home/fran directory and its files.

By default, the du command will show an error if it cannot access a file or directory.

To display the disk usage of files and file hierarchies referenced by all symbolic links, in addition to the normal files found in the /home/fran directory, type:

du -L /home/fran

To report the disk usage of the file or hierarchy referenced by the symbolic link mylink, type:

du -H mylink

du vs df: What’s the Difference?

The “disk free” (df) command gives a summary of the filesystem and mounted disks, displaying total size, used space, available space, usage percentage, and mount points.
Using the -h flag makes the output easier to read, although the numbers might be estimates.

On the other hand, the “disk usage” (du) command targets the size of a specific directory or subdirectory, offering details at the object level.
Combining du with the -sh flags provides a summarized, easy-to-read output of a directory and its contents.

Conclusion

I hope this article provided solutions for all your disk storage issues. The Linux du command seems simple at first but is incredibly powerful for disk management and deserves a space in your command-line toolkit. Doesn’t matter if you’re a Linux beginner or an expert sysadmin

With a few flags and some practice, you can quickly find storage hogs, clean up your systems, and then optimize performance.

FAQ’S

1: What does the -h option in du mean?
It means a human-readable format. It shows file sizes in KB, MB, or GB for easier understanding.

2: How can I find just the total size of a directory?

Use du -sh directory_name.

3: Is it possible to use du for remote systems?
Yes, via SSH. For example: ssh user@remote ‘du -sh /var/log’.

4: Is du superior to ls -lh for checking file sizes?
du displays actual disk usage (blocks used), while ls shows file size. Both have their uses but are different.

Areeba Nauman
Areeba is a Content Writer with expertise in web content and social media, she can simplify complex concepts to engage diverse audiences. Fueled by creativity and driven by results, she brings a unique perspective and a keen attention to detail to every project she undertakes with her creativity and passion for delivering impactful content strategies for success. Let's connect on Linkedin: https://www.linkedin.com/in/areeba-bhatti/
Unlock Benefits

Become a Community Member

SIMPLIFY SETUP, MAXIMIZE EFFICIENCY!
Setting up CyberPanel is a breeze. We’ll handle the installation so you can concentrate on your website. Start now for a secure, stable, and blazing-fast performance!