User Agents

Web browsers and everyday web tech, explained

Can I Delete .cache in Linux? Safety and Guide

· 5 min read · Cookies and Cache

In this article
  1. Understanding the XDG Base Directory Specification
  2. What Actually Lives Inside .cache?
  3. The Trade-offs of Clearing the Cache
  4. How to Safely Clean Your Cache
  5. Common Misconceptions and Risks
  6. Frequently Asked Questions

Yes, you can safely delete the .cache directory in your Linux home folder, or delete specific folders within it. This directory is designed to store non-essential, temporary data that applications can regenerate if it is missing, meaning deleting it will not break your system or lose your personal documents.

Understanding the XDG Base Directory Specification

To understand why .cache is safe to delete, it is important to understand the XDG (Cross-Desktop Group) Base Directory Specification. In the early days of Unix and Linux, applications dumped configuration files, temporary data, and logs directly into the root of the home directory, creating a cluttered mess of "dotfiles."

The XDG specification was introduced to standardize where data is stored. It defines three primary locations:

  • .config: Stores user-specific configuration settings. Deleting this will reset your app preferences to default.
  • .local/share: Stores user data that is persistent, such as save games, email archives, or local plugins. Deleting this can result in data loss.
  • .cache: Stores non-essential data that is intended to speed up the application. This is the "scratchpad" of your home directory.

Because the specification explicitly tells developers that the contents of .cache may be deleted by the user or the system at any time, well-behaved applications are written to check for the existence of a cache file and recreate it if it is gone.

What Actually Lives Inside .cache?

If you navigate to ~/.cache, you will see a variety of folders named after the applications you use. The types of data stored here vary depending on the software:

  • Web Browsers: Chrome, Firefox, and Brave store cached images, scripts, and HTML pages here. This allows pages to load faster on the second visit by avoiding a full download.
  • Thumbnailers: The GNOME and KDE file managers store small preview images (thumbnails) of your photos and videos here so they don't have to be re-rendered every time you open a folder.
  • Package Managers: Some tools store temporary download metadata or partial package files here.
  • Application State: Spotify, Discord, and other Electron-based apps store temporary session data and cached assets to reduce API calls.

The Trade-offs of Clearing the Cache

While deleting .cache is safe from a system-stability standpoint, there are performance and behavioral trade-offs to consider before you run rm -rf ~/.cache/*.

Performance Hit: The primary purpose of a cache is speed. After clearing the directory, you will notice that applications take longer to launch the first time. Web pages will load more slowly as the browser re-downloads every image and stylesheet. Your file manager will stutter briefly as it regenerates thumbnails for your image libraries.

Network Usage: If you are on a metered connection or a slow network, clearing your browser cache can be counterproductive, as it forces the system to use more bandwidth to fetch data that was already stored locally.

CPU Overhead: Regenerating complex caches (like those used by compilers or heavy media software) requires CPU cycles. On older hardware, this can cause a temporary spike in system load.

How to Safely Clean Your Cache

You do not have to delete everything in the .cache folder to reclaim space. Often, one or two specific applications are the culprits for massive disk usage.

  1. Identify the largest folders: Use a command like du -sh ~/.cache/* | sort -h to see which applications are using the most space.
  2. Targeted Deletion: Instead of wiping the whole directory, delete only the largest offenders. For example, if the browser cache is 5GB, delete only that specific subfolder.
  3. Close Applications First: While Linux generally allows you to delete files that are currently in use, it is cleaner to close the application before deleting its cache to avoid "file in use" warnings or corrupted temporary states.
  4. Use Built-in Tools: Many applications (like Firefox or Chrome) have a "Clear Cache" option in their settings. Using these is often preferable as they handle the cleanup gracefully within the app's own logic.

Common Misconceptions and Risks

A common misconception is that deleting .cache is the same as "cleaning the system." While it frees up space in the home directory, it does not touch system-wide caches (like /var/cache) or package manager caches (like /var/cache/apt or /var/cache/pacman). Those require root privileges and different commands.

Another concern is whether deleting .cache will log you out of websites. Generally, the answer is no. Session cookies and login tokens are usually stored in .config or .local/share, not in .cache. However, some apps may store temporary session tokens in the cache, meaning you might have to re-authenticate in rare cases.

Frequently Asked Questions

Will deleting .cache delete my saved passwords?

No. Passwords and authentication tokens are sensitive data and are stored in configuration files or dedicated keyring managers (like GNOME Keyring or KWallet), which are located in .config or .local/share, not in the .cache directory.

How often should I clear my Linux cache?

There is no need to do this on a schedule. You should only clear the .cache directory if you are running low on disk space or if a specific application is behaving erratically and you suspect a corrupted cache file is the cause.

Can I delete the entire .cache folder itself, or just the contents?

You can delete the entire folder. If the folder is missing, the XDG specification ensures that applications will simply recreate the directory the next time they need to store temporary data.

Is there a difference between .cache and /tmp?

Yes. The /tmp directory is usually system-wide and is often cleared automatically upon every reboot (sometimes residing in RAM). The ~/.cache directory is user-specific and persists across reboots, allowing apps to maintain speed over long periods.

Will this speed up my computer?

In most cases, no. In fact, it will temporarily slow down your computer because the system has to work harder to recreate the missing data. It only "speeds up" the system if you were critically low on disk space, which can cause the OS to swap heavily or fail to write temporary files.