How to check disk usage on a Mac in Terminal
Finder takes its time adding up folders and hides Library and dot folders. To check disk usage in Terminal on a Mac you need three commands that come with macOS, df, du and diskutil, and ncdu if you'd rather browse.
The short answer: df -h / shows the free space on the startup disk. du -sh ~/* 2>/dev/null | sort -h lists the folders in your home folder by size, biggest last. Give Terminal Full Disk Access first, or du skips protected folders with "Operation not permitted". To click through folders instead, install ncdu with Homebrew and run ncdu ~.
How do I check free disk space in Terminal?
df -h /
df -h /System/Volumes/Data
Avail is the free space, and it's the same on both lines: every volume on the internal disk shares one APFS container. Used differs. Since macOS Catalina, / is a read-only copy of macOS itself, so its Used column shows only macOS itself, around a dozen GB. Your apps and files are on the Data volume, the second line.
df -h counts in powers of 1024 (Gi), Finder in powers of 1000. df -H counts like Finder.
Why does df show less free space than Finder?
df shows space that's free right now. Finder and System Settings also count purgeable space as available: local Time Machine snapshots, iCloud files kept offline and caches that macOS removes when it needs room. The more purgeable data a Mac holds, the bigger the gap. See My Mac says the disk is full, but Finder shows free space.
What does diskutil show about my disk?
diskutil info /System/Volumes/Data
diskutil apfs list
In diskutil info, look at Volume Used Space (this volume), Container Total Space and Container Free Space (the whole disk), and SMART Status. diskutil apfs list lists every volume in the container, System, Data, Preboot, Recovery and VM, each with its Capacity Consumed, and Capacity Not Allocated for the container. Both commands only read.
How do I see folder sizes with du?
Your home folder, including hidden dot folders such as ~/.cache, then your Library, biggest last:
du -sh ~/* ~/.[!.]* 2>/dev/null | sort -h | tail -20
du -hd 1 ~/Library 2>/dev/null | sort -h | tail -15
Run the second command again on the biggest folder to go one level deeper. A few things differ from Linux, because macOS has BSD du:
-d 1instead of--max-depth=1.-xstays on one volume, so a scan doesn't wander into drives under/Volumes.-hcounts in powers of 1024, so the same folder looks a little smaller than in Finder.dutakes a minute or more on a full home folder.2>/dev/nullhides the error lines.
To list single big files instead of folders, see How to find large files on a Mac.
Why does du say "Operation not permitted"?
macOS protects Mail, Messages, Safari and other apps' data from any app you haven't allowed, Terminal included. sudo doesn't change that. To measure those folders:
- Open System Settings › Privacy & Security › Full Disk Access.
- Turn on Terminal. If it isn't listed, click the add button and choose Applications › Utilities › Terminal.
- Quit Terminal and open it again.
You can turn it off again when you're done.
How do I install ncdu on a Mac?
ncdu is a disk usage browser for the terminal. With Homebrew:
brew install ncdu
ncdu -rx ~
Use the arrow keys and Return to open a folder, s and n to sort by size or name, i for details and q to quit. -r is read-only mode. Without it, d deletes the selected item permanently after asking for confirmation; it doesn't go to the Trash. Scan your home folder or /System/Volumes/Data rather than /: ncdu's manual says it doesn't recognize macOS firmlinks, so a scan of / counts some folders twice. Homebrew also has dust, which prints a tree of the biggest folders in one go.