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:

  • -s provides a summary of the total size of the directory.
  • -h displays 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:

Check Directory Size in Mac Terminal

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:

Check Directory Size in Mac Terminal - Viewing the Size of Subdirectories

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:

Checking the Size of a Specific Subdirectory in Mac Terminal

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:

  • -h displays the sizes in a human-readable format.
  • sort -rh sorts the results in reverse order by size.
  • head -n 4 shows only the top 4 largest directories or files.

This command helps you quickly identify the largest directories in the specified folder.

Finding the Largest Directories in Mac Terminal