Caches · Terminal
How to clear the cache on a Mac with Terminal
Measure first with du, quit the apps whose caches you are clearing, then move the cache folders to the Trash with the trash command (macOS 15 and later) rather than deleting them with rm -rf. Clear only ~/Library/Caches and ~/.cache: everything in them is rebuilt. A command that deletes outright has no undo, and one stray space can point it at your whole home folder.
1. Measure before you delete
du -sh ~/Library/Caches ~/.cache 2>/dev/null
du -sh ~/Library/Caches/* 2>/dev/null | sort -h | tail -15The first line gives the totals; the second names the apps, largest last. Folders are named by the app's bundle ID, such as com.apple.Safari or com.spotify.client, so you can tell whose cache is whose. If a folder you expected prints nothing, macOS is keeping Terminal out of it; see "Operation not permitted" below.
2. Quit the apps, then move their caches to the Trash
A running app rewrites its cache while you delete it, and some crash, so quit them first. Then, on macOS 15 Sequoia or later, the trash command moves things to your Trash the way Finder does. For one app's cache:
trash ~/Library/Caches/com.example.appFor everything in your cache folder (the folder itself stays):
trash ~/Library/Caches/*On macOS 14 or earlier, which has no trash command, move a folder there yourself:
mv ~/Library/Caches/com.example.app ~/.Trash/Nothing is freed until you empty the Trash. Wait until you have opened the apps and they work, then empty it. Do the same with ~/.cache, but look inside first: command-line and AI tools keep downloads there that can take a long time to fetch again.
Why not rm -rf
Most Terminal guides give rm -rf ~/Library/Caches/*. It works, but it deletes on the spot, with no Trash and no undo, and it does exactly what it is told. Type it with one stray space, as rm -rf ~/ Library/Caches, and the shell reads ~/ as a separate thing to delete: your entire home folder. Moving to the Trash costs a step and makes every mistake recoverable.
What to leave alone
- Anything with sudo. Your caches are yours; a command that needs an administrator password is reaching into the system.
/Library/Cachesis usually small, and not worth it. /private/var/folders: macOS's temporary area, in use while the Mac runs. A restart clears it safely: see temporary files.- The rest of
~/Library. Application Support, Containers and Preferences are your apps' data, not cache: see the Library folder. /System, which macOS protects and won't let you change anyway.
"Operation not permitted"
Some folders, Safari's and Mail's among them, are kept private by macOS, and Terminal can't read or change them until you give it Full Disk Access in System Settings → Privacy & Security. For clearing caches you don't need to: skip those folders, and clear Safari's from Safari itself (how to clear the Safari cache).
Flushing the DNS cache
"Cache" also means the list of web addresses your Mac has looked up. Clearing it frees no space; it is the fix when a site still resolves to an address it has moved off. In Terminal:
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponderBoth lines ask for your administrator password, and the first site you visit after is a fraction slower. The manual page for dscacheutil says to use it only in extreme cases, so don't run it as routine.
Where the app comes in
RefreshYourMac does the measuring for you, and clears Application Caches (~/Library/Caches) and Command-Line Tool Cache (~/.cache), both rated Safe for auto removal, without a command to mistype. They are deleted outright, since apps rebuild them, and folders a more specific category covers, such as Chrome's cache, are counted there instead. In the download edition, its maintenance jobs include Flush the DNS cache, with the cost shown before you press Run. For the space-freeing side as a whole, see how to clear the cache on a Mac.
What to do next: see these numbers for your own Mac. Download RefreshYourMac free, or get it on the Mac App Store.
What it costs to have an app do this
| RefreshYourMac | CleanMyMac | MacKeeper | |
|---|---|---|---|
| Pay once | $24.99 | €119.95 on MacPaw’s store; $89.99 for CleanMyMac X on the Mac App Store | subscription only |
| Yearly | $14.99 a year, first 7 days free | $39.99/yr; €19.91/yr for the cleaning-only Essential Trio | €71.40 for the first year, 1 Mac. Their page shows it against a €119.40 list price |
| Monthly | $1.99 a month | $9.99/mo | €10.95/mo |
| Account needed | No | Yes | Yes |
Before you pay anything, both versions give you 3 free scans. CleanMyMac and MacKeeper prices read from their own pages and the Mac App Store on 27 October 2026; the full comparison is at RefreshYourMac vs CleanMyMac and MacKeeper.
Frequently asked questions
What is the Terminal command to clear the cache on a Mac?
On macOS 15 or later, quit your apps and run trash ~/Library/Caches/* to move your caches to the Trash, then empty the Trash once your apps work. On older macOS, move a cache folder to ~/.Trash with mv. Measure first with du -sh ~/Library/Caches/* | sort -h.
Is rm -rf safe for clearing caches on a Mac?
It deletes on the spot with no Trash and no undo, and a single stray space, as in rm -rf ~/ Library/Caches, makes it delete your whole home folder. Moving caches to the Trash does the same job and leaves every mistake recoverable.
How do I flush the DNS cache on a Mac in Terminal?
Run sudo dscacheutil -flushcache and then sudo killall -HUP mDNSResponder, and enter your administrator password. It frees no space; it is the fix when a site still resolves to an address it has moved off.