VMware ESXi and vSphere Cluster Management

Check File and Directory Disk Usage with du in Linux

Learn how to use the Linux du command to measure directory, subdirectory, and file disk usage, interpret blocks, and troubleshoot confusing totals.

The Linux du command reports disk usage: the amount of filesystem storage allocated to files and directories. The name du comes from “disk usage.” It is mainly used to inspect a directory and its contents, helping you find which parts of a directory tree consume storage.

A directory tree is a directory together with all of its nested files and subdirectories. A subdirectory is a directory located inside another directory. The current directory is the directory from which you run a shell command.

What du measures

du measures allocated filesystem space, usually by counting filesystem blocks. A block is a unit of storage allocation used by the filesystem. This is different from a file's apparent logical size: the number of bytes the file appears to contain.

For example, a very small file might contain only a few bytes but still occupy one complete filesystem block. As a result, the value reported by du can differ from the byte size shown by ls -l. The allocated size is the actual filesystem space reserved for content, while apparent size is the file's logical byte length.

Basic du usage

Inspect the current directory

Run du without a path argument to examine the current directory:

du

By default, the output normally contains a line for each directory beneath the current location and a final line for the current directory's aggregate total. The exact paths and numbers depend on the files present and the filesystem.

4       ./notes
12      ./projects
20      .

In this example, ./notes and ./projects are subdirectories. The final line, 20 ., represents the total usage for the current directory tree, including its nested contents.

Supply a directory path

You can give du either a relative path or an absolute path. A relative path is interpreted from the current directory:

du projects

An absolute path begins at the root directory and does not depend on your current location:

du /home/bob/example_dir

This command measures /home/bob/example_dir and the files and subdirectories below it. Nested directory usage contributes to the total reported for the parent directory.

Understanding default output units

On GNU/Linux systems, the default output is commonly expressed in 1 KiB filesystem blocks. A displayed value such as 64 therefore commonly means approximately 64 KiB of allocated space, although the exact behavior can depend on the implementation and options.

Do not assume that adding apparent file sizes will always produce the value shown by du. Allocation happens in blocks, and block rounding, sparse files, and filesystem details can make allocated usage differ from apparent size.

Human-readable output with -h

The -h option formats sizes using scaled units that are easier to read, such as K, M, and G:

du -h /home/bob/example_dir

A sample report might look like this:

12K     /home/bob/example_dir/docs
8.0M    /home/bob/example_dir/cache
8.1M    /home/bob/example_dir

The final line is the aggregate usage for the target directory tree. In this example, 8.1M /home/bob/example_dir is the total to use when you want the usage of the entire target tree, rather than just one nested directory.

How to read du output

Output elementMeaning
Size valueAllocated disk usage for the path on that line.
Path nameThe file or directory associated with the size value.
Intermediate directory lineUsage for a nested directory and the contents below it.
Final directory totalAggregate usage for the requested directory tree.

When reviewing a directory report, look at the final line for the total. Intermediate lines help you identify which subdirectories contribute most to that total.

Core du command options

OptionEffectTypical use
-hDisplays sizes in human-readable units such as K, M, and G.du -h /home/bob/example_dir
-aIncludes individual files as well as directories.du -a /home/bob/example_dir
-ahIncludes files and formats all sizes using readable units.du -ah /home/bob/example_dir

Reporting individual files with -a

Ordinary du output emphasizes directories. It does not normally list every regular file. Add -a to include individual files:

du -a /home/bob/example_dir

For a readable file-level report, combine -a and -h:

du -ah /home/bob/example_dir

An illustrative result could be:

4.0K    /home/bob/example_dir/readme.txt
12K     /home/bob/example_dir/docs/guide.txt
12K     /home/bob/example_dir/docs
16K     /home/bob/example_dir

Here, both files and directories appear. The docs line includes the usage of guide.txt, and the final line includes the usage of the complete directory tree.

Checking one directory tree

Suppose you want to inspect the example home-directory path /home/bob/example_dir. Start with a directory-focused readable report:

du -h /home/bob/example_dir

The command walks through the target and its descendants. It reports nested directories first and then reports the aggregate usage for /home/bob/example_dir. Because a parent total includes its nested directories, do not add every displayed directory line together; that would count nested usage more than once.

To see which individual files contribute to the same tree, use:

du -ah /home/bob/example_dir

du compared with filesystem free space

du answers, “How much allocated space is used by this file or directory tree?” It does not by itself provide a complete report of the capacity and free space of every mounted filesystem.

A filesystem is the storage structure that organizes files, directories, capacity, and free space. For filesystem-level capacity and free-space information, use df. A common investigation pattern is to use df to identify a full filesystem, then use du to locate large directories within it.

Important limitations

Permissions can restrict traversal

du must be able to access directories while walking the tree. If your user cannot read or traverse part of the target, the command may print a permission error and omit or incompletely measure that area.

Run the command only where you are authorized to inspect data. If appropriate, use an account with the required access, or choose a target that does not contain inaccessible paths.

Mounted filesystems can affect totals

A different filesystem may be mounted beneath a directory inside the target path. By default, content below that mount point can affect the total reported for the walk. If you need to measure only the filesystem containing the starting directory, use the implementation's option for staying on one filesystem, commonly --one-file-system on GNU/Linux.

Allocated usage is not apparent size

Differences between du and ls -l are not automatically errors. They can result from block allocation, sparse files, compression, or other filesystem behavior. First decide whether you need allocated disk usage or apparent logical size.

Troubleshooting common results

The values look larger than the file byte sizes

This usually happens because du counts allocated filesystem blocks. Several small files can each consume a complete block even when their combined apparent byte length is smaller. Use the allocated-size measurement when investigating actual storage consumption.

Individual files do not appear

Directory-focused output is normal for plain du. Add -a:

du -a /home/bob/example_dir

The units are difficult to interpret

Default output commonly shows block counts. Add -h to scale the values:

du -h /home/bob/example_dir

Permission denied messages appear

The current user cannot traverse one or more directories in the requested tree. Check that you have permission to inspect the path, use an authorized account when appropriate, or measure a path you can access.

The directory total does not explain why the disk is full

You may be comparing a directory-tree report with a filesystem-capacity problem. Use df to inspect mounted filesystem usage and free space, then use du on the relevant filesystem to locate consuming directories. Also consider mounted filesystems nested below the path and areas you could not access.

Quick reference

  • du checks usage below the current directory.
  • du /home/bob/example_dir checks a specified directory tree.
  • du -h /home/bob/example_dir uses readable size units.
  • du -a /home/bob/example_dir includes individual files.
  • du -ah /home/bob/example_dir includes files and uses readable units.
  • Read the final line to find the aggregate total for the target directory.
  • Remember that du reports allocated disk usage, while df reports filesystem capacity and free-space information.

For related guidance, see checking file and directory disk usage.