FactorPad
Build a Better Process

Linux du Command Summary with Examples

Linux du allows you to find disk utilization by file or directory.
  1. Purpose - Learn what du is for and how to find help.
  2. Options - Review a few common options and examples.
  3. Examples - Walk through code examples with du.
  4. A tip - Finish off with one more insight.
face pic by Paul Alan Davis, CFA
Updated: February 24, 2021
In this tutorial on Linux du, 52 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / du-command.html


An ad-free and cookie-free website.


Examples of the Linux du Command

Beginner

Learn to find file or directory disk space at the Linux command line.

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux du Command Summary with Examples (3:31)

Video Script

The Command and Why You Need It

Our fifty-second word, or command to memorize is du from our category System.

du allows you to show disk utilization for files and directories.

Common Linux du Options
-options description
--help Print help screen
-a, --all Show files
-h, --human-readable Print size in units of 1024 (one kilobyte)

Recall from the last video with df, we had a way to measure file system usage metrics, but it fell short of helping with files and directories, so that's what we'll do here with du.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The du command has 29 options and the argument is the file or directory to measure.

Like most commands, help is available with double-dash --help, -h reports in human-readable form, like 1k for 1 kilobyte, M for megabyte, G for gigabyte.

So why is du an important command? Well, df was good for the big picture, du now offers a more granular view, because we often need to recycle data space. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go. Let's view our directory of files with ls -og.

$ ls -og total 204 drwxr-xr-x 2 4096 Oct 14 19:53 stuff -rw-r--r-- 1 176 Oct 4 18:14 video05.txt -rw-r--r-- 1 100 Oct 10 18:42 video11.txt -rw-r--r-- 1 0 Oct 9 21:16 video16.txt -rw-r--r-- 1 45 Oct 12 10:11 video19.txt -rw-r--r-- 1 149 Oct 12 16:10 video20.txt lrwxrwxrwx 1 31 Oct 13 10:11 video21.txt -> ../ridiculouslylongfilename.txt -rw-r--r-- 1 86 Oct 13 19:40 video23.txt -rw-r--r-- 1 86 Oct 14 18:57 video24.txt -rw-r--r-- 1 1203 Oct 15 13:17 video26.txt -rw-r--r-- 1 1259 Oct 15 20:05 video27.txt -rw-r--r-- 1 352 Oct 17 21:17 video31.txt -rw-r--r-- 1 362 Oct 18 12:26 video32.txt -rw-r--r-- 1 594 Oct 18 16:27 video33.txt -rw-r--r-- 1 247 Oct 18 18:15 video34.txt -rw-r--r-- 1 247 Oct 19 14:36 video35.txt -rw-r--r-- 1 247 Oct 20 12:01 video36.txt -rw-r--r-- 1 59 Oct 20 17:06 video37.txt -rw-r--r-- 1 306 Oct 21 07:10 video38a.txt -rw-r--r-- 1 245 Oct 21 07:23 video38b.txt -rw-r--r-- 1 395 Oct 21 13:07 video38c.txt -rw-r--r-- 1 149 Oct 22 13:27 video40.txt -rw-r--r-- 1 145 Oct 24 14:19 video44.txt -rw-r--r-- 1 2678 Oct 26 15:49 video48a.txt -rw-r--r-- 1 114705 Oct 26 15:49 video48b.txt

And make note of file sizes. Then do a du optionless.

$ du 4 ./stuff 208 . $ clear

This defaults to the directory view, but this isn't very interpretable, like what does 4 and 208 mean? Right?

Next, let's see the file view using the -h option.

$ du -a 4 ./video44.txt 0 ./video21.txt 116 ./video48b.txt 4 ./stuff 4 ./video05.txt 4 ./video31.txt 4 ./video38b.txt 4 ./video11.txt 0 ./video16.txt 4 ./video48a.txt 4 ./video36.txt 4 ./video37.txt 4 ./video34.txt 4 ./video38a.txt 4 ./video40.txt 4 ./video26.txt 4 ./video19.txt 4 ./video20.txt 4 ./video23.txt 4 ./video33.txt 4 ./video38c.txt 4 ./video27.txt 4 ./video24.txt 4 ./video32.txt 4 ./video35.txt 208 .

Helpful, but not ideal.

Then, let's make it friendlier by adding -h option to the end.

$ du -ah 4.0K ./video44.txt 0 ./video21.txt 116K ./video48b.txt 4.0K ./stuff 4.0K ./video05.txt 4.0K ./video31.txt 4.0K ./video38b.txt 4.0K ./video11.txt 0 ./video16.txt 4.0K ./video48a.txt 4.0K ./video36.txt 4.0K ./video37.txt 4.0K ./video34.txt 4.0K ./video38a.txt 4.0K ./video40.txt 4.0K ./video26.txt 4.0K ./video19.txt 4.0K ./video20.txt 4.0K ./video23.txt 4.0K ./video33.txt 4.0K ./video38c.txt 4.0K ./video27.txt 4.0K ./video24.txt 4.0K ./video32.txt 4.0K ./video35.txt 208K .

Directory 4, total is 208 still, but that does look a lot better.

And last, let's go back to the ls -og.

$ ls -og total 204 drwxr-xr-x 2 4096 Oct 14 19:53 stuff -rw-r--r-- 1 176 Oct 4 18:14 video05.txt -rw-r--r-- 1 100 Oct 10 18:42 video11.txt -rw-r--r-- 1 0 Oct 9 21:16 video16.txt -rw-r--r-- 1 45 Oct 12 10:11 video19.txt -rw-r--r-- 1 149 Oct 12 16:10 video20.txt lrwxrwxrwx 1 31 Oct 13 10:11 video21.txt -> ../ridiculouslylongfilename.txt -rw-r--r-- 1 86 Oct 13 19:40 video23.txt -rw-r--r-- 1 86 Oct 14 18:57 video24.txt -rw-r--r-- 1 1203 Oct 15 13:17 video26.txt -rw-r--r-- 1 1259 Oct 15 20:05 video27.txt -rw-r--r-- 1 352 Oct 17 21:17 video31.txt -rw-r--r-- 1 362 Oct 18 12:26 video32.txt -rw-r--r-- 1 594 Oct 18 16:27 video33.txt -rw-r--r-- 1 247 Oct 18 18:15 video34.txt -rw-r--r-- 1 247 Oct 19 14:36 video35.txt -rw-r--r-- 1 247 Oct 20 12:01 video36.txt -rw-r--r-- 1 59 Oct 20 17:06 video37.txt -rw-r--r-- 1 306 Oct 21 07:10 video38a.txt -rw-r--r-- 1 245 Oct 21 07:23 video38b.txt -rw-r--r-- 1 395 Oct 21 13:07 video38c.txt -rw-r--r-- 1 149 Oct 22 13:27 video40.txt -rw-r--r-- 1 145 Oct 24 14:19 video44.txt -rw-r--r-- 1 2678 Oct 26 15:49 video48a.txt -rw-r--r-- 1 114705 Oct 26 15:49 video48b.txt

Notice how file sizes don't match? Well, if you read the short description of du by using a whatis du.

$ whatis du du (1) - estimate file space usage

It does say estimate, and it looks like it's rounding up.

A Final Tip

Okay now you know how to use du. And you know the syntax for commands, options and arguments.

One last tip about the du command. So while du does estimate data and does round, that's often good enough to see who's using up precious capacity.

Okay, thanks for visiting today. I hope this was a helpful introduction to the du command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

Connect now on YouTube and @factorpad on Twitter, so you don't have to remember to later.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / du-command.html


linux du command
du linux
linux du
unix du
du unix
linux du examples
man du
du command
disk usage linux
du linux command
linux disk space usage
linux command disk space
linux disk utilization
du tutorial
du command in linux
linux directory size
linux du tutorial
linux disk usage
du directory
linux get size of directory
linux disk space command
size of folder linux
du options

A newly-updated free resource. Connect and refer a friend today.