/ factorpad.com / tech / linux-essentials / du-command.html
An ad-free and cookie-free website.
Beginner
Learn to find file or directory disk space at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux du Command Summary with Examples (3:31)
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.
-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.
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
.
And make note of file sizes. Then do a
du
optionless.
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.
Helpful, but not ideal.
Then, let's make it friendlier by adding
-h
option to the end.
Directory 4, total is 208 still, but that does look a lot better.
And last, let's go back to the ls -og
.
Notice how file sizes don't match? Well, if you read the short
description of du
by using a
whatis du
.
It does say estimate, and it looks like it's rounding up.
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.
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
Connect now on YouTube and @factorpad on Twitter, so you don't have to remember to later.
df
command,
hit Back.free
command, click Next./ factorpad.com / tech / linux-essentials / du-command.html
A newly-updated free resource. Connect and refer a friend today.