Script To Find Large Files On Mac
Running out of disk space on your Mac? Learn how to find large files using a simple script to track storage usage over time. Keep your Mac clutter-free!
I use a MacBook Air with 8GB of RAM and a 500GB SSD. Since I work with LLMs, run Docker containers, edit podcasts, and frequently deal with large files, my disk space fills up quickly.
To manage this, I needed a way to identify large files and decide whether to delete them.
I turned to OpenWebUI and asked for a script to find large files. It provided a useful script that listed them,
find ~ -type f -size +500M
I wanted to save the output to a text file. I refined my request, asking for a human-readable file size format and a way to append the current date to the filename so I could track changes over time. This would help me identify how filesize grows—like an increase in Docker images—while ensuring other files remained unchanged. OpenWebUI generated a solid script for this.
find ~ -type f -size +500M -exec ls -lh {} + | awk '{ print $9 ": " $5 }' | sort -k2 -h
This script works. But if a file name has spaces, it will output only the first segment of the file name (as in "Gen" of "Gen Study"). So I asked it to output the full filename.
#!/bin/bash
find ~ -type f -size +500M -exec stat -f "%N %z" {} + | awk '{size=$NF; unit="B"; if (size>=1024) {size/=1024; unit="KB"}; if (size>=1024) {size/=1024; unit="MB"}; if (size>=1024) {size/=1024; unit="GB"}; printf "%s: %.2f %s\n", substr($0, 1, length($0)-length($NF)), size, unit}' | sort -k2 -h > "$(date +%Y-%m-%d)-largefiles.txt"
I saved it in a dedicated folder where I keep similar scripts, added the folder’s path to my .bashrc
file.
export PATH="/Users/uname/batch:$PATH"
I also gave execute permission: chmod +x find_large_files.sh
Now I can execute the script from anywhere in the terminal.
With a single command, I can scan my Mac’s user directory for large files, log the results, and compare them over time. This makes it easier to track and delete unnecessary files, keeping my storage under control.
Under: #code