How to Check Disk Space on Mac Terminal


How to Check Disk Space in Mac Terminal

Checking the disk space on your Mac can be efficiently done using the Terminal. The df and du commands are commonly used for this purpose, providing information about available space, usage, and detailed disk utilization for files and directories.

Using the df Command

The df command, which stands for "disk filesystem," shows information about the overall disk usage of your mounted file systems. Here's how to use it:

df -h

The -h flag stands for "human-readable" and displays the sizes in a format that is easier to understand (GB, MB, etc.).

Output Explanation:

After running the df -h command, you’ll see output similar to this:


Filesystem      Size   Used  Avail Capacity  Mounted on
/dev/disk1s1    250G   120G    130G    50%    /
  • Filesystem: The disk or partition being reported.
  • Size: Total size of the filesystem.
  • Used: Amount of space that has been used.
  • Avail: The available free space.
  • Capacity: The percentage of the total space that has been used.
  • Mounted on: The directory where the file system is mounted.

Viewing Disk Space of a Specific Directory

To check the disk space used by a specific directory, you can add the directory path to the df command. For example, to check the space used in the Documents directory:

df -h ~/Documents/

Using the du Command

The du (disk usage) command provides information about how much disk space is being used by specific files and directories. This command is more granular and can be useful for analyzing which folders or files are consuming space.

Basic Usage of du Command

To see the disk usage of files in the current directory, use:

du -sh *

The -s flag summarizes the disk usage, and -h makes the output human-readable. The output will show the disk usage of each file and folder in the current directory.

Output Explanation:


1.4G   Documents
2.5M   Downloads
512K   Pictures
  • Size: Disk space used by the file or folder (e.g., 1.4G, 512K).
  • Folder/File: Name of the folder or file.

Checking Disk Usage of a Specific Directory

To check the disk usage for a specific directory, use the following format:

du -sh /path/to/directory

For example, to see the disk usage of your Documents folder:

du -sh ~/Documents/

Detailed Disk Usage

If you want to see a detailed breakdown of disk usage for every subdirectory, you can use the du command without the -s flag:

du -h /path/to/directory

This will display each directory and file in the specified path, along with the disk space they consume.

Disk Space Report Using diskutil

Another tool to check disk space is the diskutil command. This command provides detailed information about the volumes on your system:

diskutil list

This will show all the disks and partitions attached to your Mac.

Example Output


/dev/disk1
   #:                        TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.3 GB   disk1
   1:                        EFI EFI                     209.7 MB   disk1s1
   2:                 Apple_APFS Container disk2         500.0 GB   disk1s2

In this example:

  • disk1: The identifier for the physical disk.
  • EFI: A small partition used by the system.
  • Container disk2: The partition that contains your data.

Conclusion

Using the df and du commands, you can easily monitor and manage the disk space usage on your Mac. These tools allow you to get a quick overview of your storage and identify directories and files that consume the most space.


Python Libraries