317

When I use disk usage analyzer and scan my home folder, the .cache folder in my home directory always shows up with a decent bit of things in it.

Would it be okay for me to delete the contents of this folder or would it damage something?

3

6 Answers 6

175

To answer the question, IMO you can delete all of .cache with no long term detrimental effects.

If your .cache is growing large, it might be better to look at the contents and determine what application is making it large and re-configure a bad acting application (rather than simply deleting .cache when it grows too large).

Another directory that can take up a lot of space (and/or save an embarrassing bit of evidence) is the .thumbs directory. Many files in .thumbs seem to be duplicates.

To clean (just take care with the -rf flag and other directories ;)

rm -rf ~/.thumbs/*

When you are new to Ubuntu/Linux it is hard to know what you can and can not delete in your home directory. For the most part you can delete most anything in your home directory, programs or applications that require .cache (or other dot files such as .local) will re-create them.

Most of the time, at worst, you will lose custom configurations, but no real harm to the system.

I would not advise you start a habit of deleting things you do not understand in your home directory, back it up or use a test account. If in doubt, the safe thing would be to make a back up or move the file.

mv .cache .cache_backup

You can then restore from backup if needed.

Definitely do NOT start deleting things you do not understand outside of your home directory.

7
  • 6
    I get really nervous about any command that starts rm -rf, so I'd recommend using gvfs-trash ~/.thumbs instead
    – wjandrea
    Aug 25, 2017 at 21:44
  • 1
    @wjandrea simply use rm -r then ;) ... the -f is anyway only needed for special cases or if rm was aliased to be rm -i ... May 26, 2020 at 20:29
  • 1
    @wjandrea "This tool has been deprecated, use 'gio trash' instead." Jan 31, 2021 at 0:52
  • 4
    There is also trash-cli (at least on my Kubuntu box), easily installed with sudo apt install trash-cli for those wary of rm -rf commands.
    – Spam Hater
    Jun 8, 2021 at 5:38
  • 1
    In Debian 11 (Gnome Shell 3.38) thumbnails are in ~/.cache/thumbnails.
    – ChennyStar
    Apr 13 at 12:20
94

I just discovered that my backup disk was filling up with stuff from .cache (I guess applications are cleaning their own cache, but I don't delete backups so it's getting huge). So I'm excluding .cache from my backup list, but I noticed that .cache has stuff from TEN YEARS AGO, software I had forgotten I ever used!

This will delete everything in your .cache that was last accessed more than a year ago

find ~/.cache/ -type f -atime +365 -delete

If you're nervous about running it, this will show you what's going to be deleted:

find ~/.cache/ -depth -type f -atime +365 

I'm using 'access time' for that, you could also try 'creation time' by using -ctime (although I've found many cache files which are years old but still accessed). Thanks to @n33rma for the edit suggestion.

3
  • 3
    Exactly my issue, too! My daily backups were consistently ~1.7GB. Now that I deleted ~/.cache, they're only ~0.1 GB! Good suggestion re: the -atime flag, too. What I do is put a similar find command in my crontab, also for my /tmp/ folder; I use -atime +1 with no problems.
    – Geremia
    Aug 25, 2016 at 14:44
  • 2
    issue : du ~/.cache | sort -n to see sort by dir size Oct 7, 2016 at 16:33
  • My JetBrains folder with 9Go inside ~/.cache, lol. May 5, 2022 at 9:25
52

It is generally safe to delete it. You might want to close all graphical applications (e.g. banshee, rhythmbox, vlc, software-center, ..) to prevent any confusion of the programs accessing the cache (where did my file go all of a sudden!?).

It can easily have a size of 100+ MB, so if you want to free up disk space, do it.

As already pointed out by BretD and Dylan McCall, the type of files are partial downloads, browser cache, media files like icons, etc, used to speed up future access to the same files.

Another thing to keep in mind: removing an application does not necessarily delete the relevant ~/.cache/removed_prog folder; in this case those files just take space and are not used. Those can definitely be deleted.

2
  • 1
    If you're going to wipe ~/.cache, best to wipe it all at once (so you don't confuse any application with an inconsistent/partial state), then restart immediately after (just in case some application that uses files in ~/.cache is still running in the background). Feb 11, 2016 at 3:57
  • dude. i see everyone saying this with taking the utmost precaution of deleting anything from .cache, because there is a very tiny chance some program may malfunction due to erasing that folder. so, lets just say it. if you dont know what to delete, or what is safe to delete ; dont delete it. so therefor, it would be best to leave this folder alone i guess, because you might screw up your browser, or some other program you did not suspect. Feb 15, 2020 at 10:00
7

Here is a script that I keep on all my machines for finding disk hogs:

$ cat ~/bin/hog
#! /usr/bin/env bash
#
# -*- mode: shell-script -*-

case $# in
(0) dir='.';;
(1) dir=$1;;
(*) echo "usage: hog <dir>"
  exit 1;;
esac

du -s --one-file-system $dir/* $dir/.[A-Za-z0-9]* | sort -rn | head

Also, on my machine, I have my home directory mounted with the noatime option, so I modified the above to:

find ~/.cache -depth -type f -mtime +365 -delete

which keys off modification time.

You also might want to put this in your crontab, with crontab -e and add the lines:

# Clean out ~/.cache
13 3 * * 0 chronic find ~/.cache -depth -type f -mtime +365 -delete
1
  • To make the size human readable, you can pipe hog to | numfmt --field=7 --from-unit=1000 --to=iec or you possibly can pipe that before head. I didn't bother to figure out why adding -h to du messes it up.
    – mchid
    Nov 20, 2022 at 2:54
4

I would recommend not deleting it. I am not a Linux expert (though I hope to be!) and don't know the specifics of the file system structure, but you can examine what exactly is in the folder by going into your home folder and hitting ctrl+h to show hidden folders. You can then go in the .cache folder and see what's in there.

Just from a quick peek on my system I know that banshee stores album art in the cache folder (don't know why exactly), chrome has data in the cache folder, a lot of programs keep logs in the .cache folder, and other stuff.

I am not sure if these files are all just there temporarily for speed increase purposes (like browser cache) or if this "cache" contains files for some other purpose (as the speed increase of browser cache is to counteract excessive use of bandwidth by re-accessing files on a server, whereas there should be no discernible difference in r/w times for a different file location on the hard disk).

I hope someone knows more about this than I do and can give you a better response.

6
  • Yes, I agree that it isn't a good idea to delete .cache. If possible, use the program that creates the relevant folder. Deleting Chrome's cache, for example, should preferably be done via Chrome. If a program doesn't offer a visible means of managing its cache, it may be safer to leave it alone unless one really knows.
    – user25656
    Feb 7, 2012 at 5:13
  • 43
    The idea of .cache is that it is deletable (see standards.freedesktop.org/basedir-spec/basedir-spec-latest.html). Applications shouldn't depend on it, and I really have never noticed an application doing it wrong. Banshee is indeed a funny case, but it's a great example: BretD is right that you probably won't want to delete all your cache, because it is generally there for a good reason. It takes a long time for Banshee to get cover art. It can do it again, but it will look ugly in the interim. Feb 7, 2012 at 6:41
  • 1
    @vasa1 or you can use a GUI-based disk usage analyzer. I think Baobab, should be available on Ubuntu (I use it in Debian) Nov 25, 2013 at 2:33
  • 4
    @DylanMcCall That link to the standard makes your comment more useful than all the other answers. If you made that comment an answer, I'd upvote it. Apr 21, 2015 at 5:41
  • 3
    Why post "I don't know" as an answer? This just added to my confusion....
    – wogsland
    Apr 8, 2021 at 10:53
-6

deleting .cache will delete most configuration settings to web applications. First to notice are the web browsers and mail clients.

Same applies for folder .mozilla. For example it will remove all accounts from Thunderbird and you have to re create them again. Regarding to web browsers it will delete the history and some of the content settings

Other than that there is no trouble of deleting these files.

1
  • 11
    you are confusing .config with .cache. settings are stored in .config which should never be deleted. However anything, make that EVERYTHING in .cache can be deleted. (any program dumb enough to store application settings in there has no place to be in linux ever)
    – Rob
    Jul 6, 2019 at 3:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .