Commands.page Logo

How to Check Total Directory Size in Ubuntu Linux

This guide explains how to determine the storage space used by a specific folder and its contents within the Ubuntu operating system. You will learn the primary command-line tool used for this task, along with the necessary flags to display the results in a human-readable format. By following these steps, you can quickly manage disk space and identify large directories on your system.

The Du Command

The command used to calculate the total size of a directory including subdirectories is du, which stands for disk usage. To see the total size of a specific folder, open your terminal and type the following command:

du -sh /path/to/directory

Understanding the Flags

The flags used in this command modify the output to make it useful for quick checks:

Practical Examples

To check the size of your home directory, you can run:

du -sh ~

If you are currently inside the folder you want to check, you can use a dot to represent the current directory:

du -sh .

In some cases, you may encounter permission errors if the directory contains files owned by the root user. If this happens, prepend sudo to the command to grant the necessary privileges:

sudo du -sh /path/to/directory

This method provides an immediate and accurate measurement of disk usage for any folder on your Ubuntu machine.