Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running Ubuntu on a limited-size SSD, so I count every GB. Now, the ~/.cache folder grew to 1.7 GB (various applications such as Chrome, Spotify etc. filled it up) and now I'm wondering if there's a way to limit the size of this cache?

I saw some solutions suggesting adding a cronjob to delete old files using some awk trickery, but I don't know how would all these applications handle if random files were just deleted (or is that OK?). Also, this solution doesn't recursively search the folder.

share|improve this question
What's your usage like? On 24/7, many clean boots per day or something else? – Oli Sep 26 '13 at 16:16
If I understood you correctly - I mostly put my machine to sleep whenever I can and only do a clean shutdown when I know I won't use it for some time (or I did some upgrades). – metakermit Sep 27 '13 at 10:51
up vote 2 down vote accepted

If you were going to use any technique off that question, I'd go for the find technique in a cron job and alter it to check the size:

@daily    find /home/username/.cache/ -atime +7 -size 50M -delete

Obviously have a play around with that. You may wish to exclude certain paths from the query as .cache contains a lot of things that can be a real pain in the bum to regenerate (like thumbnails for some media players or photo viewers).

Of course the other option is shifting everything to tmpfs by adding something like the following to your /etc/fstab:

tmpfs        /home/username/.cache/    tmpfs   defaults,noatime,mode=1777   0  0

And that will store everything in RAM (after a sudo mount -a or a reboot). Obviously this means that as soon as you power off, you've lost everything in there. This is probably only suited to a desktop that rarely gets restarted and that has lots of RAM.

The two could be used in combination.

The other option is to move cache off to slower, cheaper media. If you've space for a big magnetic disk in your computer, that's often a quick and easy way (either with a symlink or a bind-mount) to spread things over multiple disks.

Either that or move something else that isn't speed dependant (like documents, music, etc) to the slow disk, giving you more room for cache on the SSD.

share|improve this answer
Thanks for you help, Oli. Yes, I see what you mean - it's a trade-off between having a more responsive OS and saving disk space. I'll think about the methods you suggested and see which one suits me best - probably the last one, as it's a laptop and I want to minimise re-computing stuff to save battery. – metakermit Oct 2 '13 at 8:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.