Skip to main content

Command Palette

Search for a command to run...

🚀 “My Mac Was Slower Than Ever — Until I Ran This One Terminal Command (M1/M2 Users Must Try This!)”

Here’s how a 2-minute script freed 10+ GB of junk and made my M1 MacBook Air feel brand new.

Published
3 min read
🚀 “My Mac Was Slower Than Ever — Until I Ran This One Terminal Command (M1/M2 Users Must Try This!)”
V

With over 9 years of experience as in IT, I have led technology operations across diverse industries, ensuring robust IT infrastructure, network security, and team development.

My expertise spans managing IT infrastructure & operations, IT policy, and backup/disaster recovery. My expertise also includes IT asset management, Google Workspace & Office 365, endpoint security, DLP, and cross-platform systems (Windows/Linux/Mac OS) etc.

Additionally, I hold certifications in Google IT Support, CCNA, and IBM Cybersecurity, reinforcing my commitment to continuous learning and delivering robust technology solutions.

Thank you for your time and consideration.

Best regards, Vishal Mathur

💻 The Problem

If you’ve owned a Mac for more than a few months, you’ve probably noticed it — apps take longer to open, Safari hangs for a second too long, and that fan that never used to spin suddenly won’t stop.

Even the mighty Apple Silicon M1 or M2 chips aren’t immune to cache bloat — hidden folders full of temporary files, logs, and system junk that silently eat away your storage and speed.

I used to dig through Finder manually, deleting random cache folders. It worked… kind of. Then I found a faster, cleaner, geek-approved way — one simple Terminal script.


⚙️ The Fix: A One-Line Cache Cleanup Script

Here’s the exact script I used to clear my Mac’s system and app caches safely.

Works perfectly on macOS Monterey, Ventura, Sonoma, and newer (including M1 & M2 chips).

🧠 Step 1: Open Terminal

You’ll find it under:

Applications → Utilities → Terminal

Or hit Command + Space, type “Terminal”, and press Enter.

🧩 Step 2: Create the Script

Type this command:

nano ~/Desktop/clear_cache.sh

Then paste the script below:

#!/bin/zsh
echo "🧹 Starting full Mac cache cleanup..."

sudo -v

echo "→ Clearing user cache..."
rm -rf ~/Library/Caches/*

echo "→ Clearing system cache..."
sudo rm -rf /Library/Caches/*

echo "→ Clearing temporary files..."
sudo rm -rf /private/var/folders/*

echo "→ Flushing DNS cache..."
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder

echo "→ Clearing Safari cache (if exists)..."
rm -rf ~/Library/Safari/*
rm -rf ~/Library/Caches/com.apple.Safari/*
rm -rf ~/Library/Caches/Metadata/Safari/*

echo "→ Clearing log files..."
sudo rm -rf /private/var/log/*
sudo rm -rf ~/Library/Logs/*

echo "✅ Cache cleanup complete! Restart recommended."

Save it by pressing:

Control + O → Enter → Control + X

⚡ Step 3: Make It Executable & Run

Run these two commands:

chmod +x ~/Desktop/clear_cache.sh
sudo ~/Desktop/clear_cache.sh

Enter your Mac password (it won’t show as you type).

Now sit back — your Mac will do a deep clean of all caches, temp files, and logs.

When it’s done, restart your Mac.


💥 The Result

I instantly freed over 12 GB on my M1 MacBook Air. Apps launched faster, and Safari finally stopped beach-balling. It felt like a fresh install — without reinstalling macOS.

Here’s what it cleaned:

✅ User caches

✅ System caches

✅ DNS cache

✅ App temp files

✅ Safari junk

✅ Log files


💡 Bonus Tip: Make It Permanent

Want to reuse it anytime?

Run:

sudo mv ~/Desktop/clear_cache.sh /usr/local/bin/clearcache
sudo chmod +x /usr/local/bin/clearcache

Now you can just type:

sudo clearcache

from any Terminal window, whenever your Mac feels sluggish. 💨


🧠 Why It Works

macOS caches improve performance — until they don’t. Over time, they pile up from app updates, web browsing, and system logs. Apple doesn’t provide a single “Clear All” button, but this script does exactly that — safely.

It doesn’t touch your personal files or system libraries — just removes old, rebuildable caches.


✨ Final Thoughts

If your Mac feels slower, don’t rush to upgrade or reset.

Try this first — it’s quick, reversible, and shockingly effective.

🔹 Took me: 2 minutes

🔹 Freed: 12 GB

🔹 Improvement: Immediate

More from this blog

What Are Tokens — And Why Should You Care?

The hidden unit of measurement that shapes every conversation you have with Claude. You type a message to Claude. You hit send. A response flows back in seconds. Simple, right? But beneath that seamless exchange, something interesting is happening — your words are being sliced into tiny linguistic units called tokens before Claude ever "reads" them. Tokens are the atomic unit of language for large language models. They're not characters, and they're not always full words. They sit somewhere in between — and understanding them unlocks a clearer picture of how AI language models actually work, why they have limits, and how to work with those limits instead of against them. So what exactly is a token? Think of tokenisation as breaking text into the most useful chunks for a model to learn from. Common words like "the" or "and" are usually one token. Longer or rarer words might get split into two or three pieces. Punctuation, spaces, and newlines all count too. Example — how this sentence gets tokenised Claude under stands language through tok en isation . As a rough rule of thumb: 100 tokens is about 75 words, or a short paragraph. A typical novel runs around 100,000 words — that's roughly 133,000 tokens. Claude's extended context window can hold the equivalent of several books at once. The context window: Claude's working memory Every conversation with Claude happens inside a context window — a fixed-size buffer that holds everything Claude can "see" at once. This includes your entire conversation history, any documents you paste in, system instructions, and Claude's own responses. Once the window fills up, older content scrolls out of view. Claude doesn't forget it in the human sense — it simply can't read past what fits. This is why very long conversations can occasionally feel like Claude loses track of something said much earlier.

May 20, 20263 min read
What Are Tokens — And Why Should You Care?
V

Vishal Mathur - IT Consultant and AI Prompt Engineer

30 posts

With over 9 years of experience as in IT, I have led technology operations across diverse industries, ensuring robust IT infrastructure, network security, and team development.