Safe to delete ~/.cache ?

I just noticed my ~/.cache folder is almost 2 GB, which is quite a bit for my small partition. Since it's called cache, would it be safe to delete it without breaking anything?

It depends what is in it. :wink:

Check that out with du

du -sh ~/.cache/*
1 Like

Yeah, it's 1,8 GB. But it's cache, so I don't know how important anything in it is.

That command lists what is in it by size.

If you use yay, it might be your cached AUR packages. As long as you don't mind losing old packages it would safe to delete.

As for anything else, there is a good chance you could delete it safely but there is really no guarantee of that. I would look and see what makes up that 1.8GB and target the worst offenders.

A huge portion is made up of wine and brave and firefox. I suppose they could be safe to delete...

EDIT: DISREGARD THIS POST. I have been advised (implied) in the next post to avoid Bleachbit.

I use Bleachbit to do periodic disc cleanups.
You can select the apps/areas of the system you want it to inspect and clean through its GUI. It will show you a list of files and paths for you to confirm before deletion.

You can set up your own custom paths.

Another version of that would be:

du -h -d1 ~/.cache

Yes, though you'd be safer deleting its content rather than the directory itself, e.g.:

rm -fr ~/.cache/*

This isn't recommended. There are some threads about it... I think it can be overly aggressive and end up breaking stuff.

4 Likes

Perhaps, would it be better to make a lite script for deleting .cache/*, executing pacman -Scc, cleaning /var/log/journal, etc rather than relying on bleachbit? Cause personally I'd rather learn where everything is, since I hope Manjaro is more consistent than Windows, and clean it myself.

Cause that's what I did. I freed up a lot more gigabytes than I thought, and after emptying ~/.cache some of my programs are now starting up 3 times faster than before, particularly wine programs which needed up to 5-6 seconds to boot up before and now run in 1-2.

as a sidenote, there is also the possibility to mount the ~/.cache as tmpfs, assuming you have a decent amount of ram avaiable.

the pros:

  • much faster read/write access in comparison to hdd/ssd
  • privacy-friendly
  • no need for manual intervention, as the cache is flushed on every shutdown

before that you should definitely know the contents of your cache. loosing huge databases or that kind of probably turns out rather conterproductive, as they need to be repopulated on every reboot.

you have been warned :slight_smile:

1 Like

Oh! I'd better not use it then. Thanks for the head's up.

Thanks guys, so far I've made this cleanup script which seems to work fine so far. Do you recommend adding anything more to it?

sudo pacman -Scc

sudo rm /var/log/journal/62ac6cd816cf4f4db6b6a633e785231f/*

rm -r ~/.cache/*

rm ~/.wine/drive_c/windows/Installer/*

rm -r /var/tmp/pamac-build-kiko/*

I'd rather recommend using some of the journalctl-Switches
--vacuum-size, --vacuum-time or --vacuum-files= depending on what you're trying to do.

2 Likes

You're doing it wrong. If you care about the size of the journal, you can simply restrict its size with a new config file like:
sudo nano /etc/systemd/journald.conf.d/00-journal-size.conf
and write there down something like this:

[Journal]
SystemMaxUse=1400M

where 1400M is 1400 megabytes limit.

3 Likes

Alright, thanks, I'll change to that. However how is that different from directly editing /etc/systemd/journald.conf in the spot where it says #SystemMaxUse= ?

I'm not sure but I guess the main .conf file may be overwritten with stock values as new systemd update comes.
Yeah. You can check it yourself:
$ pacman -Qo /etc/systemd/journald.conf

/etc/systemd/journald.conf is owned by systemd 242.29-1

Holy crap, my .cache directory is 15.7GB

By the way guys, if I wanted to move a directory to tmpfs, how would I do that? Do I just replace .cache with a symlink? If so where should that symlink lead to? A .cache directory in /run or what?

Bleachbit also runs on Windows. I remember about the year 2000, I ran across it and I thought it was cool. So I used it on one of the computer that I was in charge of, and BOOM! It deleted most of the 'System' directory. Lucky for me, I always had a copy of the current windows release, so I just reinstalled it. I checked its web site, and it does look a little better but if you do not know all of the facts about what you are deleting it can be bad news.

gary

1 Like

I have a script that regularly shreds (mechanical drive) everything inside ~/.cache/. If you have any programs open at the time, they may crash during this process (i.e. Firefox). But if everything is closed you should be able to delete it without a problem.

My script also cleans out the Pacman cache, System Journal (via switches), etc. I'm not on Linux atm otherwise I would post it in a gist for you guys.

Him @kik4444, I hope you find these useful:

Journal size limit
https://wiki.archlinux.org/index.php/Systemd/Journal#Journal_size_limit

Clean journal files manually
https://wiki.archlinux.org/index.php/Systemd/Journal#Clean_journal_files_manually

I set mine in 50M:

SystemMaxUse=50M

In the terminal, try

sudo nano /etc/systemd/journald.conf

And then from there, you can set your journal size limit manually.

1 Like