13

The .cache directory is full of volatile, non-essential files.

I would like to move it to a more appropriate partition, i.e. faster and not backed up.

I believe that ~/.pam_environment file is appropriate for this but am not sure if is the best or if it is documented properly or working properly.

2
  • How are you preserving /some/other/place/.cache between reboots? If one moves .cache to, say, /dev/shm, when the box is rebooted /dev/shm/.cache is missing and so ~/.cache is dangling symlink.
    – user257772
    Mar 13, 2014 at 8:06
  • Related guide for google chrome here: joeyconway.com/blog/2011/09/11/…
    – Kzqai
    Feb 23, 2016 at 18:31

1 Answer 1

27

If you don't care about keeping the stuff there across reboots, you can use tmpfs to store the cache.

Set something like the following in /etc/fstab:

tmpfs /home/someuser/.cache tmpfs defaults,size=512M 0 0

Now, your .cache will be stored in memory instead of on disk, though if you have insufficient memory it could end up being swapped out.

A more traditional approach would be to move the directory to wherever you like and symlink it as appropriate:

mv ~/.cache /some/other/place
ln -s /some/other/place/.cache ~/
6
  • This is working well. I had hoped to use pam-env as it is the "preffered" way, but this works, and if it isn't broke, don't fix it. BTW Chrome is much speedier now! Dec 24, 2011 at 17:21
  • ~/.pam_environment is for setting environment variables, which has nothing to do with the task at hand. Besides, though some claim that .pam_environment is preferred, I don't think that's necessarily so, considering how few people (according to Google) are using it. .bashrc is good enough for me. Dec 25, 2011 at 1:42
  • 2
    I think second option have one error, second line should be ln -s /some/other/place/.cache ~/.cache, not just link to ~/, how apps will know home is cache folder, not old .cache inside home? Mar 14, 2018 at 12:39
  • 1
    If no filename is specified, then ln will use the original one. So, while your example will also work, there's no mistake in my answer. Mar 14, 2018 at 15:31
  • how to verify if the fstab line really works as it should?
    – acgbox
    Apr 12, 2022 at 21:15

You must log in to answer this question.

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