How to Find the Size of a Directory in Ubuntu

The Capacity Audit Vector

When administering a Linux server, identifying which specific directories are consuming the most hard drive space is a constant necessity. If your primary partition hits 100% capacity, database engines will crash and log files will cease writing. If you simply execute the standard ls -l command to view a folder’s details, Ubuntu will confusingly report the size of the directory file itself (usually 4KB), not the cumulative size of the gigabytes of data stored inside that directory.

How to Find the Size of a Directory

You must use a dedicated Disk Usage command, instructing the kernel to drill down into the target folder, mathematically sum the size of every single nested file, and return the total aggregate value.

1. Open your terminal application or connect to your server via SSH.
2. The utility you require is du (Disk Usage). To make the output legible, you must combine it with two specific flags. Execute the following command structure:

du -sh /var/log/

3. Command Breakdown:
* du: Invokes the disk usage utility.
* -s (Summarize): This is the most critical flag. Without it, the command will print thousands of lines detailing the size of every single file individually. The `-s` flag suppresses the noise and only prints the final, grand total.
* -h (Human-readable): Instructs the utility to output the final number in Megabytes (M) or Gigabytes (G) rather than a massive, confusing string of raw kilobytes.
* /var/log/: Replace this with the absolute path to the directory you wish to investigate.

4. Press Enter. Depending on the size of the directory, the terminal may pause for a few seconds as it calculates. It will then output a single, clean line of data (e.g., `4.2G /var/log/`).

Get the best tech tips delivered straight to your inbox.

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