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

When you use the standard ls -l command to view the contents of a directory in Linux, the file sizes it reports for folders are completely useless. It typically shows “4096” bytes for a folder, regardless of whether that folder is empty or contains 500 gigabytes of high-definition video. To actually calculate the true size of a directory and all the files hidden inside it, you must use the du (disk usage) command.

The Problem with the Default du Command

If you navigate to a directory and simply type du, Linux will immediately print a massive, scrolling list of every single file, sub-folder, and hidden item inside that directory, along with a number representing its size in kilobytes. If you are scanning a busy web server folder, this output is an unreadable flood of data that does not actually answer your question.

To make the command useful, you must use specific formatting flags.

How to Get a Human-Readable Summary

Most of the time, you just want to know the total size of the specific folder you are currently standing in, formatted in a way that makes sense (Megabytes or Gigabytes, rather than thousands of Kilobytes).

To do this, use the -s (summary) and -h (human-readable) flags together:

du -sh

Press Enter. Instead of a scrolling list, the terminal will print a single line: the total combined size of the current directory (e.g., 14G .), making it immediately clear how much space the folder is consuming.

You can also point the command at a specific folder without navigating into it first. For example, to check the total size of the system log folder, type:

sudo du -sh /var/log

How to Find the Biggest Sub-Folders

If you know your “Documents” folder is massive, but you don’t know which sub-folder inside it is causing the problem, the summary command isn’t enough. You need Linux to calculate the size of every immediate sub-folder, without drowning you in a list of individual files.

You do this by limiting how “deep” the command is allowed to search using the --max-depth flag.

du -h --max-depth=1

This brilliant command tells Linux: “Calculate the human-readable size of everything, but only show me the totals for the folders sitting right here in front of me, do not show me what is inside them.”

This will print a neat, short list of your immediate sub-directories and their total sizes, allowing you to instantly identify which specific folder is eating your hard drive.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the best tech tips delivered straight to your inbox.

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

Receive our best articles and tips delivered straight to your inbox.