Linux online course

Check File and Directory Disk Usage with du in Linux

Learn how to use the Linux du command to inspect directory trees, find space-consuming files, read human-readable totals, and interpret disk usage correctly.

The Linux du command reports the disk space used by files and directory trees. It is useful when you need to find which directories or files are consuming storage.

Disk usage is the amount of filesystem storage allocated to content. This can differ from a file's apparent byte length because files are stored in filesystem blocks. In other words, du measures allocated space rather than merely displaying a file's nominal size.

A directory tree consists of a directory, its subdirectories, and the files beneath them. The current directory is the location from which you run a shell command.

What the du Command Reports

du examines a directory tree and reports usage for the directories it finds. This makes it useful for narrowing down where space is being consumed. By default, it emphasizes directory entries instead of listing every ordinary file individually.

Unlike a command that simply prints file lengths, du reports filesystem blocks consumed by the content. A small file may occupy a whole allocation block, and special filesystem features can also make allocated space differ from apparent size.

Basic du Usage

Run du without an argument to inspect the current directory and the directory tree below it:

du

The output commonly contains one line for each subdirectory, followed by a final line for the current directory. The final line is the total allocated space for the examined tree.

12      ./documents/projects
8       ./documents
4       ./images
28      .

In this example, ./documents/projects and ./images are subdirectory entries. The final . line represents the complete current directory tree. The values are illustrative; actual output depends on the files and filesystem.

You can provide either an absolute path or a relative path:

du /home/bob/example_dir
du ./example_dir

Both commands inspect the named directory and its descendants. An absolute path starts from the filesystem root, while a relative path is interpreted from the current directory.

Understanding Default du Output

Default output is commonly shown in 1 KiB blocks, where one KiB is 1,024 bytes. The exact display can be affected by the operating system implementation, environment settings, and command options, so treat the default format as block-oriented rather than as a convenient byte measurement.

Output elementMeaning
A path for a subdirectoryThe allocated usage for that subdirectory and everything below it.
A path for an individual file when -a is usedThe allocated usage associated with that file.
The final line for the requested directoryThe total allocated usage for the requested directory tree.

Without -a, ordinary files are generally not printed as separate entries. Their usage is included in the totals for the directories containing them.

Use Human-Readable Units

The -h option changes block-oriented values into scaled units that are easier to read, such as K, M, and G:

du -h

To inspect a specific directory with readable values, add its path:

du -h /home/bob/example_dir

A result might look like this:

1.2M    /home/bob/example_dir/logs
3.4M    /home/bob/example_dir/data
5.0M    /home/bob/example_dir

The final line is the total allocated space for /home/bob/example_dir and everything beneath it. The displayed unit may vary according to the amount of space, so a larger tree can appear in megabytes or gigabytes.

Report Individual Files with -a

Use -a to include individual files as well as directory entries:

du -a /home/bob/example_dir

This produces a more detailed report. It still includes directory totals, but it also shows paths for files. A large directory tree can produce a very long output.

Combine -a and -h to get per-file and per-directory usage in readable units:

du -ah /home/bob/example_dir

Short options can be combined when the command supports that form. Here, -ah means the same basic options as -a -h.

4.0K    /home/bob/example_dir/readme.txt
1.2M    /home/bob/example_dir/logs/app.log
1.2M    /home/bob/example_dir/logs
3.4M    /home/bob/example_dir/data
5.0M    /home/bob/example_dir

Key du Options

OptionEffectExample
-hDisplays sizes using human-readable units such as K, M, and G.du -h /home/bob/example_dir
-aIncludes individual files in addition to directory entries.du -a /home/bob/example_dir
-ahIncludes individual files and displays their sizes in readable units.du -ah /home/bob/example_dir

How to Interpret du Results

To find large content, compare the reported values and look for the largest displayed paths. A large subdirectory is a useful place to investigate next. Using -ah can then reveal which individual files contribute to that directory's usage.

Remember that a directory's reported usage includes the content beneath it. For example, the total for data includes files inside data and any nested subdirectories.

Common Troubleshooting Cases

Values are difficult to read

If output consists of block counts, du is using its default unit format. Add -h:

du -h /home/bob/example_dir

Expected files are missing

Default output focuses on directories, so ordinary files may not appear individually. Add -a:

du -a /home/bob/example_dir

There are too many entries

A deeply nested directory, especially when used with -a, can produce a large report. Run du on a narrower target directory, or omit -a when directory totals are sufficient.

The total does not match a manual sum

Parent directory totals include their children. Do not sum nested directory entries together. Treat the final line as the total for the requested directory tree.

Practical du Workflow

  1. Start with du -h in the current directory or against a specific path.
  2. Compare the directory values to identify large subdirectories.
  3. Run du -ah on a large subdirectory to inspect its files.
  4. Remember that parent totals overlap with child totals when interpreting the report.

For related command-line foundations, review Linux command-line topics, learn about showing the full path of shell commands, and explore Bash.

Exam-Relevant Notes

  • du reports disk usage for files and directory trees.
  • Disk usage represents allocated filesystem space and may differ from apparent file size.
  • Running du with no path examines the current directory.
  • The default report commonly uses 1 KiB blocks and emphasizes directories.
  • -h produces human-readable units.
  • -a includes individual files.
  • The final line is the total for the requested directory hierarchy.
  • Adding parent and child directory values double-counts nested content.