Check Directory Size in Mac Terminal
Checking the size of directories in Mac Terminal is a useful way to understand how much storage space is being used by a particular folder.
The Terminal offers several powerful commands, such as du, which allow you to see the size of a directory and its contents.
In this guide, we’ll show you how to use the du command to check the size of directories in the Mac Terminal.
Using the du Command to Check Directory Size
The du command, short for “disk usage,” is used to estimate file and directory sizes. By default, it lists the size of all the files and subdirectories within a directory. To check the total size of a directory, use the following syntax:
du -sh /path/to/directory
In this command:
-sprovides a summary of the total size of the directory.-hdisplays the output in human-readable format (GB, MB, etc.).
For example, to check the size of your Documents directory, run the following command:
du -sh ~/Documents
This will return the total size of the Documents folder in an easily understandable format, such as:

Viewing the Size of Subdirectories
To see the size of all the subdirectories within a directory, you can omit the -s flag and just use -h. This will list the sizes of all the files and folders within the directory. For example:
du -h ~/mac_terminal_tutorials
The output will look something like this:

This command lists each subdirectory’s size, and the last line shows the total size of the parent directory.
Checking the Size of a Specific Subdirectory
If you want to check the size of a specific subdirectory within a directory, simply specify the subdirectory path. For example, to check the size of the folder1 inside the Documents folder, use:
du -sh ~/Documents/folder1
This will return the total size of the subdirectory:

Finding the Largest Directories
If you want to find the largest directories inside a specific folder, you can use the following command to list and sort the results by size:
du -h ~/Documents | sort -rh | head -n 4
Here’s what the options mean:
-hdisplays the sizes in a human-readable format.sort -rhsorts the results in reverse order by size.head -n 4shows only the top 4 largest directories or files.
This command helps you quickly identify the largest directories in the specified folder.

