How to Find the Total Size of a Directory in Linux Using the du Command

When you use the standard ls -l command in the Linux terminal, it accurately displays the file sizes of individual text documents or images. However, if you point ls at a massive folder (like /var/log), it will usually output a tiny number like 4096. This is because ls only measures the metadata size of the folder itself, not the actual cumulative size of the thousands of files contained inside it.

To accurately calculate the total, cumulative disk usage of an entire directory tree, you must use the du (Disk Usage) command.

How to Use the du Command

If you simply type du and press Enter, the terminal will instantly flood with thousands of lines of text as the utility aggressively calculates the size of every single sub-folder individually before finally printing the grand total at the bottom in raw kilobytes.

This is almost unreadable for humans. You need to use flags to filter the output.

The Summarize and Human-Readable Flags

To get a clean, single-line answer representing the total size of a specific folder, you should combine the -s (summarize) and -h (human-readable) flags.

  1. Open your Linux terminal.
  2. Type the following command, replacing /var/log with the actual path of the folder you want to inspect:
    du -sh /var/log
  3. Press Enter.

The terminal will pause for a fraction of a second while it calculates the math, and then it will output a single, clean line of text, such as: 4.2G /var/log. The -h flag automatically converts the raw kilobytes into easily understandable Megabytes (M) or Gigabytes (G).

Troubleshooting Permission Errors

If you attempt to run du -sh against a system-level folder (like /root or /etc), the terminal will spit out dozens of “Permission denied” errors, and the final calculation will be highly inaccurate because the tool was blocked from reading the locked files.

To force the tool to read absolutely everything inside a restricted directory, you must run the command with elevated privileges using sudo:

sudo du -sh /var/log

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.