The Internet Browser is the single most important program for today’s users, no matter what system; Linux, Windows, Android, MacOS X, you name it.
But no matter if you use Firefox, Chrome/Chromium, Opera, they all keep flooding your home directory with cruft that you never asked for; mostly ~/.configand ~/.cache. While I can understand (grudgingly) the need to store some site-specific data in ~/.config, I simply have zero tolerance for all that cruft in ~/.cache; I found myself with my home directory growing from ~900 MiB to 1.5 GiB because of all that stuff.
I don’t want it. I don’t need it. But cleaning that stuff up (manually or with a script) only helps until you start your browser again; and in no time at all, it dumps half the Internet into your home directory again.
And backing up the home directory has become a chore; no more a simple rsync -av call, no, you need to explicitly exclude all that browser cache garbage.
There must be a better approach to this!
Well, there is. With a little symlinking and making use of /tmp now being on tmpfs, i.e. a RAM disk, I managed to move that stuff into that self-emptying garbage bin; welcome to temporary housing until the next reboot.
sh@meteor:~> ls -l ~/.cache
lrwxrwxrwx 1 sh users 13 Jan 5 14:50 /work/home/sh/.cache -> /tmp/cache-sh
sh@meteor:~> df -Th /tmp/cache-sh
Filesystem Type Size Used Avail Use% Mounted on
tmpfs tmpfs 7.6G 694M 6.9G 9% /tmp
sh@meteor:~> du -hs /tmp/cache-sh
687M /tmp/cache-sh
sh@meteor:~>
Good riddance! Hope you’ll like that next reboot!
All this takes is a little script:
sh@meteor:~> cat $(which mv-cache-tmp)
#!/bin/bash
#
# Move ~/.cache to /tmp/$USER-cache (on tmpfs, i.e. a RAM disk)
#
# (c) 2025 Stefan Hundhammer <Stefan.Hundhammer@gmx.de>
# License: GPL 2.1
OLD_CACHE=$HOME/.cache
TMP_CACHE=/tmp/cache-$USER
# This may contain several directories, separated by whitespace
EXTRA_CRUFT="$HOME/.config/WarThunder/.game_logs"
EXTRA_CRUFT="$EXTRA_CRUFT $HOME/.config/chromium"
function show_du()
{
DIR=$1
if [ -d $DIR ]; then
if [ ! -L $DIR ]; then
du -hs $DIR
fi
fi
}
# Create the base dir in /tmp
if [ ! -d $TMP_CACHE ]; then
mkdir -v $TMP_CACHE
else
du -hs $TMP_CACHE
fi
# Show disk usage of the old directories
show_du $OLD_CACHE
for CRUFT in $EXTRA_CRUFT; do
show_du $CRUFT
done
# Move the cache dir to /tmp
rm -rf $OLD_CACHE
ln -sf $TMP_CACHE $OLD_CACHE
ls -ld $OLD_CACHE
# Move the other cruft dirs to /tmp/cruft/
for CRUFT in $EXTRA_CRUFT; do
if [ -e $CRUFT ]; then
DIR=$(basename $CRUFT)
TARGET="$TMP_CACHE/cruft/$DIR"
# echo "Moving $CRUFT -> $TARGET"
mkdir -p $TARGET
rm -rf $CRUFT
ln -sf $TARGET $CRUFT
ls -ld $CRUFT
fi
done
# Show some results
echo
ls -ld $TMP_CACHE
echo
/bin/df -hT $TMP_CACHE
echo
I put this into the autostart of my Xfce4 session, so it runs for every graphical login.
I have been using this since early December now without noticing any bad side effects.
