36

When I scanned my $HOME directory with baobab (Disk Usage Analyzer), I found that ~/.cache is consuming about half a GB.

I also tried to restart and again check size but no difference.

So, I am planning to rm -rf ~/.cache. Let me know Is it safe to clear ~/.cache?

Anthon
  • 78,313
  • 42
  • 165
  • 222
Pandya
  • 23,898
  • 29
  • 92
  • 144

4 Answers4

30

It is safe to clear ~/.cache/, new user accounts start with an empty directory anyway. You might want to log out after doing this though since programs might still use this directory. These programs can be found with this command:

find ~/.cache -print0 | xargs -0 lsof -n

In my case I would most likely be fine with just closing Firefox before removal.

Lekensteyn
  • 20,173
  • 18
  • 71
  • 111
11

Yes it is safe, but before you just throw it all away check what is in there. The files under .cache are used to speed up your programs e.g. by not causing downloads when not necessary. Some content there might immediately have to be downloaded or recreated again.

du -sm ~/.cache/*

will give you a list and you can selectively remove any of those subdirectories based on your usage of the programs, disc space used etc.

You could logout and back in as Lekensteyn indicated, but at most the programs owning the subdirectories have to be restarted if running.

Anthon
  • 78,313
  • 42
  • 165
  • 222
  • 2
    I typically use `du -sm ~/.cache/* | sort -n` in order to help prioritizing (and maybe set `shopt -s dotglob` if there are dotfiles). – Lekensteyn Jun 11 '15 at 08:12
  • @Lekensteyn I use that sometimes as well, but it has the disadvantage that you have to wait until it scans everything before sorting takes place and lists the output. With the 20 or so entries I have in `~/.cache` the overview is easily kept. And anyway there is always the same set of culprits: `thumbnails`, `chromium`, `vlc`, `pip` ;-) – Anthon Jun 11 '15 at 08:17
4

It is safe, since by definition it only contains things that programs can recreate. As others point out it's probably a good idea to log out after clearing it.

A better question is perhaps: is it useful? It would fill back up again pretty quickly, unless you've significantly changed your usage patterns, and in the mean time would decrease the performance of the programs which use it while they recreate the information which was in there. You're probably better off leaving it alone.

  • 1
    I agree with your answer, but there's an exception: removing cached files from uninstalled unwanted applications. –  Oct 04 '15 at 19:58
0

You can always rename '.cache' to '.cache.old' to see what problems may arise.