Clear Cache Command Guide for Windows, Mac, and Linux
In this article
Clearing your cache via command line allows you to force a system or application to refresh its stored temporary data, which resolves software glitches, removes corrupted files, and frees up disk space. Depending on what you are trying to fix—whether it is a DNS issue, a system-level memory bottleneck, or a specific application's temporary storage—the specific command will vary. Using the command line is often faster than navigating through graphical user interfaces and allows for precise control over which cache directories are purged.
What You'll Need
- A computer running Windows, macOS, or a Linux distribution.
- Access to a terminal application (Command Prompt, PowerShell, Terminal, or Bash).
- Administrative or root privileges (Sudo) for system-level cache clearing.
- Knowledge of which specific cache you intend to clear (DNS, System, or Application).
Step-by-Step
- Identify the Cache Type: Before entering a command, determine if you need to clear the DNS cache (to fix website loading issues), the system cache (to improve performance), or a package manager cache (to fix software installation errors).
- Open the Command Interface:
- Windows: Press the Windows Key, type "cmd" or "PowerShell", right-click the application, and select "Run as Administrator".
- macOS: Press Command + Space, type "Terminal", and press Enter.
- Linux: Press Ctrl + Alt + T or open your preferred terminal emulator.
- Execute DNS Cache Commands:
- Windows: Type
ipconfig /flushdnsand press Enter. You should see a confirmation message stating the DNS Resolver Cache was successfully flushed. - macOS: Depending on your version, use
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder. You will be prompted for your admin password. - Linux (systemd-resolved): Use
sudo resolvectl flush-cachesorsudo systemd-resolve --flush-caches.
- Windows: Type
- Clear System Temporary Files (Windows):
- To clear the temporary folder via command line, use
del /q /f /s %temp%\*. The/qflag ensures quiet mode,/fforces deletion of read-only files, and/sdeletes files from all subdirectories.
- To clear the temporary folder via command line, use
- Clear Package Manager Cache (Linux):
- For Debian/Ubuntu systems, use
sudo apt-get cleanto remove retrieved package files from the local repository cache. - For Fedora/CentOS (DNF), use
sudo dnf clean allto remove cached metadata and packages.
- For Debian/Ubuntu systems, use
- Clear PageCache, Dentries, and Inodes (Linux):
- To clear the kernel's memory cache, use
sudo sync; echo 3 | sudo tee /proc/sys/vm/drop_caches. Thesynccommand ensures all cached data is written to disk before the drop occurs.
- To clear the kernel's memory cache, use
- Verify the Results: Restart the application or browser you were having trouble with, or use a tool like
pingto verify that DNS requests are now resolving to the correct IP addresses.
Common Mistakes
One of the most frequent errors is failing to run the terminal with administrative privileges. On Windows, running a standard Command Prompt instead of an elevated one will result in an "Access Denied" error when attempting to flush DNS or delete system temp files. Similarly, on macOS and Linux, forgetting the sudo prefix prevents the system from executing commands that modify protected system directories.
Another common mistake is using the rm -rf command on Linux or macOS without double-checking the directory path. For example, typing sudo rm -rf / cache (with an accidental space after the slash) would attempt to delete the entire root directory rather than the cache folder, which can lead to total system failure. Always verify your syntax and paths before pressing Enter.
Users also frequently confuse the DNS cache with the browser cache. Running ipconfig /flushdns will not clear your Chrome or Firefox history or cached images; those must be cleared within the browser settings or by deleting the specific browser profile folders via the command line, which is a much more complex process.
Tips
To save time, you can create a batch file (.bat) on Windows or a shell script (.sh) on Linux/macOS. By grouping multiple cache-clearing commands into a single script, you can perform a "deep clean" of your system with one double-click or a single command execution. For instance, a Windows batch file could combine ipconfig /flushdns, ipconfig /release, and ipconfig /renew to fully reset network connectivity.
When clearing Linux memory caches, avoid doing so on a production server unless absolutely necessary. The kernel manages cache efficiently; manually dropping caches forces the system to read data from the slower disk instead of the fast RAM, which can cause a temporary performance dip known as "cold cache" latency.
If you are clearing caches to troubleshoot a website, try using a "Hard Refresh" in your browser (Ctrl + F5 on Windows, Cmd + Shift + R on Mac) before resorting to command-line DNS flushing. This often solves the problem without needing terminal access.
Troubleshooting
If you receive a "Command not found" error, it usually means the utility is not in your system's PATH environment variable or you are using the wrong command for your specific OS version. For example, older versions of macOS used different dscacheutil parameters than newer versions. Check your OS version and refer to the official documentation for that specific build.
If the ipconfig /flushdns command returns an error saying the DNS service is not running, you may need to restart the DNS Client service. In Windows, you can do this via the Services app (services.msc) or by using the command net start dnscache, though this service is often protected and may require a system reboot to reset.
When deleting temporary files on Windows, you will likely see several "The process cannot access the file because it is being used by another process" messages. This is normal. It means those specific cache files are currently active in a running program. You can ignore these errors or close all open applications and try again to clear a larger percentage of the cache.
Frequently Asked Questions
Will clearing my cache delete my personal files?
No. Cache commands target temporary storage areas designed for transient data. They do not affect your documents, photos, or application settings. However, you may be logged out of some websites if you clear browser-related session caches.
How often should I clear my system cache?
Generally, you should only clear the cache when you encounter a specific problem, such as a website not updating or a system slowdown. Constant clearing can actually slow down your computer because the system has to rebuild the cache from scratch.
Is it safe to use sudo for cache commands?
Yes, provided you are using a trusted command. System-level caches are owned by the root user, so sudo is required to modify them. Just be extremely careful with the rm command to avoid deleting critical system files.
Why does my internet feel slower after flushing DNS?
This is a temporary effect. The DNS cache stores the IP addresses of sites you visit frequently so your computer doesn't have to ask a DNS server every time. After a flush, your computer must perform a new lookup for every site, which takes a few extra milliseconds.
Can I clear the cache for a specific app via command line?
Yes, but you must know the exact file path to that application's cache folder. Once you have the path, you can use the del (Windows) or rm (Unix) commands to empty that specific directory.