## 19.3 Cleanup Cache

20200102

A user’s local cache can be a place where data is collected but not necessarily required. If you’ve run out of disk space then the ~/.cache/ directory is one location to consider cleaning up.

The cache is a place for applications to store temporary data that might allow the application to run more speedily. It is useful to review its contents occasionally. It is actually insightful to do so, particularly for privacy issues. For example, depending on what tools you use over many years, have a look at ~/.cache/unity-lens-video for thumbnails of videos you may have watched locally. You’ll also find browser caches, font caches, etc. Some may be quite old if you’ve used your computer for many years. The following might be informative:

$du -sh ~/.cache 1.6G /home/kayon/.cache$ ls -ltR ~/.cache | most
[...]
/home/kayon/.cache/fontconfig:
[...]
/home/kayon/.cache/simple-scan:
[...]
/home/kayon/.cache/wallpaper:
[...]
/home/kayon/.cache/chromium:
[...]

The space consumed might just be the 1.6G of disk storage you need to recover to keep your login active!

The general wisdom is that removing the cache is okay, and is expected not to be relied upon long term. Nonetheless it is best to ensure you have a minimum of applications running whilst clearing out the cache to avoid confusing any that are not well written.

To remove files in the cache that have not been accessed for the past year, use the following, first to check what files will be removed, and to then delete them, using find:

$find ~/.cache/ -depth -type f -atime +365 -exec ls -lht {} \;$ find ~/.cache/ -type f -atime +365 -delete

$du -sh ~/.cache 365M /home/kayon/cache A cautious approach to cleaning up the cache is to selectively remove particular space horders: $ du -sh .cache/* | grep M
[...]
309M    .cache/BraveSoftware
567M    .cache/chromium
$rm -rf ~/.cache/chromium ~/.cache/google-chrome ~/.cache/thumbnails To fell it all in one foul sweep (be careful): $ rm -r ~/.cache/*