How to move the user cache directory [~/.cache] out of the /home directory to another partition

13,139

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 ~/
Share:
13,139

Related videos on Youtube

keepitsimpleengineer
Author by

keepitsimpleengineer

Retired from… System Admin (Unix/Linux) Oracle DBA/Developer GUI Application Developer Simulation Engineer·Real-time Hardware in Loop Technical Project Engineering College Instructor (programming) Flight Test Engineer Aerospace Engineer Flight Test Data Analysis …after 45 years. About time! Now I futz around with my six computers, two Windows systems and six Linux systems two archlinux, one Debian and two Ubuntus. Help out friends and post stuff that I have worked through and think might help others. Also dabble in cooking, photography, music and goofing off.

Updated on September 18, 2022

Comments

  • keepitsimpleengineer
    keepitsimpleengineer over 1 year

    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.

    • Admin
      Admin about 10 years
      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.
    • Kzqai
      Kzqai about 8 years
      Related guide for google chrome here: joeyconway.com/blog/2011/09/11/…
  • keepitsimpleengineer
    keepitsimpleengineer over 12 years
    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!
  • Scott Severance
    Scott Severance over 12 years
    ~/.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.
  • Alexei Martianov
    Alexei Martianov about 6 years
    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?
  • Scott Severance
    Scott Severance about 6 years
    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.
  • acgbox
    acgbox about 2 years
    how to verify if the fstab line really works as it should?
  • Scott Severance
    Scott Severance about 2 years
    After mounting everything (mount -a or reboot) type mount by itself without any arguments. You'll get a list of everything that's currently mounted. Look through the list to verify if everything is as expected.