How to Check Directory Disk Space Usage on Ubuntu
Table of Contents
This tutorial explains how to show the total amount of disk space a specific directory is using (including all subdirectories).
To find out how big each individual file is, see this tutorial.
To find out the total disk space usage by an entire disk volume, see this tutorial.
Step 1. Open a Terminal Session
If you're using an Ubuntu laptop or desktop, you can press
Ctrl + Alt + T on your keyboard to open a new terminal window. If you're using a remote Ubuntu server, you can connect using SSH to open a new terminal session.
To check disk space usage for the current directory:
You should see output like:
-h option tells the command to show human-friendly units such as
M for megabytes,
G for gigabytes, etc.
-d 0 option tells the command to show output for "depth level 0" - i.e., only the total amount used by the directory, not individual listings for subdirectories.
As usual, you can also combine the options and get the same output:
If you also want to see disk usage by all subdirectories in the current directory, you can run:
If you want to limit the subdirectories listed to just the immediate subdirectories, you can use depth level 1:
You can keep increasing the depth levels to show subdirectories of subdirectories, and so on.
If you want to see information for directories other than your current directory, you can just list the directory paths at the end of the command. For example, to see disk usage by the three directories
/usr/local/bin you can run:
If you see a "permission denied" message for some directories like:
you can add
sudo to the beginning of the command:
Because of how Linux file systems store data, a file whose size is x bytes may take up more or less than x bytes of disk space. For example, a 6-byte file storing the word "hello" may take an entire 4 KB block of disk space.
To get the total sum of all actual file sizes in the current directory (as opposed to disk usage), you can call
du with the