How to move the user cache directory [~/.cache] out of the /home directory to another partition
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 ~/
Related videos on Youtube
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, 2022Comments
-
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 about 10 yearsHow 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 about 8 yearsRelated guide for google chrome here: joeyconway.com/blog/2011/09/11/…
-
-
keepitsimpleengineer over 12 yearsThis 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 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 about 6 yearsI 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 about 6 yearsIf 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 about 2 yearshow to verify if the fstab line really works as it should?
-
Scott Severance about 2 yearsAfter mounting everything (
mount -a
or reboot) typemount
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.