DEV Community

Cover image for How to Safely Clear System Cache Using the Terminal: A Simple Guide
K-kibet
K-kibet

Posted on

How to Safely Clear System Cache Using the Terminal: A Simple Guide

What Is System Cache?

System cache consists of temporary files created by your operating system and apps. These files improve performance, but over time they accumulate and can:

  • Take up storage,
  • Slow down the system,
  • Cause outdated or corrupted cache-related issues.

Clearing cache doesn’t delete personal files; it only removes temporary system files.


Clearing System Cache: Conversation Breakdown

1. Alex’s First Question: “How do I clear cache from the terminal?”

Sam explains that cache clearing depends on your operating system. Below are the correct terminal commands per OS.


Linux: Clear System File Cache

Linux makes it easy to clear memory cache using the terminal without deleting actual files.

To clear pagecache, dentries, and inode caches:

sudo sync
echo 3 | sudo tee /proc/sys/vm/drop_caches
Enter fullscreen mode Exit fullscreen mode

This frees RAM by clearing cached filesystem data. It is safe and widely used by system administrators.

One-line command:

sudo sh -c 'sync; echo 3 > /proc/sys/vm/drop_caches'
Enter fullscreen mode Exit fullscreen mode

macOS: Clear System Cache

macOS stores various system, application, and user caches. You can safely remove them using:

Clear user-level cache:

sudo rm -rf ~/Library/Caches/*
Enter fullscreen mode Exit fullscreen mode

Clear system-level cache:

sudo rm -rf /Library/Caches/*
Enter fullscreen mode Exit fullscreen mode

Restart after clearing cache:

sudo shutdown -r now
Enter fullscreen mode Exit fullscreen mode

A reboot ensures macOS rebuilds fresh cache files.


Windows: Clearing System Cache via Command Line

Windows uses multiple cache locations. Here’s how to clear the most important ones:

Clear Temp folder:

del /q /f /s %TEMP%\*
Enter fullscreen mode Exit fullscreen mode

Clear Prefetch cache:

del /q /f /s C:\Windows\Prefetch\*
Enter fullscreen mode Exit fullscreen mode

Clear Windows Update cache:

net stop wuauserv
del /q /f /s C:\Windows\SoftwareDistribution\Download\*
net start wuauserv
Enter fullscreen mode Exit fullscreen mode

Or use built-in Disk Cleanup:

cleanmgr
Enter fullscreen mode Exit fullscreen mode

Alex’s Final Question: “Does Disk Cleanup (cleanmgr) delete actual files?”

Sam clarifies:

Yes, Disk Cleanup can delete files — but only safe temporary files.

It removes things like:

  • Temporary system files
  • Recycle Bin contents
  • Thumbnail cache
  • Windows Update leftovers
  • System error logs

You manually check what you want to delete. Nothing is deleted unless you confirm it.

Important Warning:

Avoid deleting Previous Windows installation, unless you’re sure you don’t need to roll back a system update.


Final Thoughts

Clearing system cache is a safe and effective way to:

  • Free disk space
  • Fix software glitches
  • Speed up your machine

Just make sure you use the correct commands for your operating system, and always double-check before deleting anything.

Whether you're like Alex, curious about how things work, or like Sam, someone who assists others through technical issues, clearing cache via the terminal is a powerful skill every computer user should know.


Top comments (0)