Ubuntu: Get the Size of a Directory via the Terminal CodeUnit 29 JUL 2011

When using the terminal to navigate your way through your Ubuntu or any other Linux distro, it is actually pretty easy to quickly see how big a particular directory or folder is in terms of size.

The command to use is du, short for Disk Usage. It’s main purpose is to gather and summarize how much of your disk space is being used up by either files or directories in the Linux system.

Basic usage (with the -h switch to report back the size in easy to understand user friendly units) is:

du -h /home/craiglotter

This will recursively list all folders and their respective sizes as well as the total size of the selected folder in the appropriate size unit.

Adding the -s for summarize switch will return only the total file size for the selected directory (this is still recursive in case you were wondering).

du -sh /home/craiglotter

If you want the size for all files in the current directory also displayed, add an asterisk to your query. Similarly, if you want only files of a specific type listed with their respective sizes, modify the asterisk with the desired file extension.

In practice:

du -sh /home/craiglotter *


du -sh /home/craiglotter *.txt


Related Posts:

About Craig Lotter

Software developer, husband and dad to two little girls. Writer behind An Exploring South African. I don't have time for myself any more.