Sub topic 7
Finding Large Files and Folders in Terminal
The Storage settings pane gives you a good overview, but it can't always tell you which folder or file is using the space. Terminal can. This chapter covers three commands: df, du, and find. Together they take you from "the disk is nearly full" to "this specific folder is the cause."
Prerequisites
This chapter assumes you:
- Can open Terminal (in Applications > Utilities) and run a command.
- Know that
~means your home folder, for example/Users/yourname. - Understand from earlier chapters that APFS volumes share free space and that some space is purgeable.
All commands in this chapter only read information. None of them delete anything. Deleting is covered in the chapter on safe deletion.
The three-step method
The approach narrows the search in stages.
dfshows how full the disk is.dushows which folders hold the space.findshows which individual files are large.
Step 1: Check the volume with df
df stands for "disk free". It reports used and available space for each mounted file system.
df -h /System/Volumes/DataThe -h flag means "human-readable", so sizes appear as G (gigabytes) and T (terabytes) instead of raw block counts. The path /System/Volumes/Data is the volume that holds your user data. Since macOS Catalina, the system is split into a read-only system volume and a Data volume, and your files live on the Data volume.
The output looks like this (your numbers will differ):
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/disk3s5 460Gi 310Gi 95Gi 77% 2.1M 996M 0% /System/Volumes/DataRead it as follows:
- Size is the total capacity that the volume can use.
- Used is the space taken by files.
- Avail is the free space that is available right now.
- Capacity is the share of the volume in use.
Why df may not match Storage settings
Two differences surprise people.
- Purgeable space.
dfcounts purgeable files, such as local snapshots and some caches, as used. The Storage settings pane counts them as available, because macOS can remove them when it needs room. Sodfoften reports less free space than System Settings. - Shared free space. APFS volumes on the same container share one pool of free space. The
Availnumber reflects the container, not a private slice for this one volume.
Neither tool is wrong. They answer different questions: df asks how much is free right now, and Storage settings asks how much could be made free.
Step 2: Find big folders with du
du stands for "disk usage". It adds up the size of everything inside a folder. Run it on your home folder with a depth limit and sort the result:
du -h -d 1 ~ 2>/dev/null | sort -hr | head -n 10This is a pipeline of three commands. Each part has a job:
| Part | What it does |
|---|---|
| `du -h -d 1 ~` | Reports the size of your home folder and each folder directly inside it. `-h` gives readable sizes. `-d 1` limits the depth to one level. |
| `2>/dev/null` | Discards error messages, such as "Operation not permitted" for protected folders. |
| `sort -hr` | Sorts the lines by size, largest first. `-h` understands units like `G` and `M`. `-r` reverses the order. |
| `head -n 10` | Keeps only the first ten lines. |
The first line of the output is your home folder itself, which is the total. The lines after it are the largest folders inside.
Typical output:
212G /Users/sam
88G /Users/sam/Library
51G /Users/sam/Movies
30G /Users/sam/Documents
18G /Users/sam/DownloadsDrilling down
Once you know Library is the biggest folder, run the same command on it:
du -h -d 1 ~/Library 2>/dev/null | sort -hr | head -n 10Repeat this until you reach a folder whose contents you recognize. Typical large entries inside ~/Library are Application Support, Caches, Containers, and Group Containers. Containers is where sandboxed apps keep their data.
Gotchas with du
- Slow on large folders.
duhas to visit every file. A home folder with hundreds of thousands of files can take a minute or more. - Hidden errors. Because of
2>/dev/null, a folder that macOS blocks will be silently skipped, so its size may be missing from the total. Terminal needs Full Disk Access (System Settings > Privacy & Security) to read protected locations such as parts of~/Library. Without it, your totals can be too low. sort -his required. Plainsort -rcompares text, so9Gwould rank above100G. Always use-hwith human-readable sizes.- Sparse files and clones. APFS can store a copy of a file without using extra space until the copy is changed.
dumay count both copies in full, so a folder can look larger than the space it uses on disk. Disk images and virtual machine files are often sparse as well. - Folders with spaces. If you type a path that contains spaces, wrap it in quotes, for example
du -sh "$HOME/Library/Application Support".
Getting one total
To see the total for a single folder, use -s for "summarize":
du -sh ~/DownloadsStep 3: Find big files with find
du points to folders. find locates individual files that match a condition. This command lists every file over 1 GB in your home folder:
find ~ -type f -size +1G -exec ls -lh {} + 2>/dev/nullHere is what each piece means:
find ~starts searching in your home folder and goes through every subfolder.-type flimits matches to regular files, not folders.-size +1Gmatches files larger than 1 gigabyte. Use+500Mfor 500 megabytes, or+100Mfor a smaller threshold.-exec ls -lh {} +runsls -lhon the matches. The{}stands for the matched file names, and the+passes many files to onelscall, which is faster than runninglsonce per file.2>/dev/nullhides permission errors.
The output shows permissions, owner, size, date, and path for each file:
-rw-r--r-- 1 sam staff 4.2G Mar 3 09:14 /Users/sam/Movies/project-final.mov
-rw-r--r-- 1 sam staff 2.7G Jan 19 18:02 /Users/sam/Downloads/macOS-installer.dmgA note on size units in find
find -size rounds up to whole units. A file of 1.1 GB counts as "2G" for the purposes of the comparison, so -size +1G matches files that round up to more than one unit, which means files larger than 1 GB. When you need an exact cutoff, use bytes with the c suffix, for example -size +1000000000c.
Useful variations
Search a different folder, such as the whole Data volume. This needs Full Disk Access and takes longer:
sudo find /System/Volumes/Data -xdev -type f -size +2G 2>/dev/nullThe -xdev option keeps find on one file system, so it does not wander into other mounted drives. Use sudo with care: it runs the command with administrator rights. For a read-only search this is safe, but never paste a sudo find command that includes -delete or -exec rm unless you understand exactly what it matches.
Show only files that have not been modified in a year, which are good candidates to review:
find ~/Downloads -type f -mtime +365 -size +100M -exec ls -lh {} + 2>/dev/null-mtime +365 matches files whose modification time is more than 365 days ago.
Putting it together: a worked example
Suppose df reports 97% capacity.
- Run
df -h /System/Volumes/Data. Avail is 14 GB on a 460 GB volume. - Run the
dupipeline on~. The result shows~/Libraryat 88 GB. - Run it on
~/Library. The result showsApplication Supportat 40 GB. - Run it on
~/Library/Application Support. A folder named after a video editor uses 38 GB. - Run
findinside that folder with-size +1G. It lists several render cache files that the app can recreate.
You now know exactly what is using the space. Whether you may delete it is a separate decision. Check the app's own settings first, since many apps have a "clear cache" button that is safer than deleting files by hand.
Common mistakes
- Reading
dutotals as exact. They are good for ranking, but they can differ fromdfbecause of clones, sparse files, and permissions. - Forgetting Full Disk Access. Missing permission is the most common reason for totals that look too small.
- Using
lsinstead ofdufor folders.ls -lshows the size of the folder entry itself, not its contents. - Sorting without
-h. The order will be wrong. - Pasting commands with
-delete. Search first, delete later and separately.
Exercise
You run du -h -d 1 ~ | sort -r | head -n 5 and the largest folder listed is 9.1G, even though you know your Movies folder holds more than 40G. What is the most likely cause, and how do you fix the command?
Show answer
sort -r without -h compares the lines as text, so 9.1G sorts above 40G because the character 9 comes after 4. Use sort -hr so that sort understands the unit suffixes and orders by actual size.
Exercise
Write a command that lists files larger than 500 MB in ~/Downloads that were last modified more than 180 days ago, showing sizes in readable form.
Show answer
find ~/Downloads -type f -size +500M -mtime +180 -exec ls -lh {} + 2>/dev/null
Exercise
df -h /System/Volumes/Data reports 12 GB available, but Storage settings shows 60 GB available. Give one likely explanation and one command to investigate it.
Show answer
Storage settings counts purgeable space, such as Time Machine local snapshots and removable caches, as available, while df counts it as used. Run tmutil listlocalsnapshots / to see whether local snapshots exist.