When managing an Ubuntu Linux server or desktop, you will inevitably encounter situations where your storage drive is filling up rapidly. While the df command is excellent for viewing the overall free space on your entire hard drive, it cannot tell you which specific folders are consuming that space. To pinpoint massive directories and find out exactly how much storage a specific folder is using, you must use the du (Disk Usage) command.
Understanding the Basic du Command
The du command, by itself, is often overwhelming. If you simply open a terminal and type du, the system will recursively list every single file and subfolder in your current directory, printing their sizes in raw kilobytes. This results in an endless wall of text that is almost impossible for a human to read or interpret usefully.
How to Get a Readable Summary (The -sh Flags)
To make the output useful, you need to append two specific flags to the command:
- -s (Summarize): This tells the command to only print a single total size for the directory, rather than listing the size of every individual file inside it.
- -h (Human-readable): This translates the raw kilobyte numbers into easy-to-read formats like Megabytes (M) or Gigabytes (G).
The combined command looks like this: du -sh /path/to/directory
Example 1: Checking a Specific Folder
If you want to know exactly how much space your “Downloads” folder is consuming, you would run:
du -sh ~/Downloads
The terminal will output something like: 4.2G /home/username/Downloads
Example 2: Checking System Folders (Requires Sudo)
If you are investigating system directories (like checking how large your log files have grown), you will need root privileges to read the files.
sudo du -sh /var/log
How to Find the Largest Folders Inside a Directory
Often, you know a directory is large, but you need to know which sub-folders inside it are the culprits. You can use the asterisk (*) wildcard to summarize all items within a directory, and then pipe (|) that output into the sort command to order them by size.
Run this command to see the size of everything inside the current directory, sorted from smallest to largest:
du -sh * | sort -h
This is the most powerful way to quickly identify space-hogging directories on your Ubuntu system and regain control of your storage.