My cache directory in /var/lib/snapd/cache is taking up a lot of space, and there are lots of files in there with hardlink count 1. Since they are not linked to any snaps retained, is it safe for to remove all those cache files manually, or is there any CLI way to remove them?
I wonder about this as well. In general, I would expect to see cache files in /var/cache instead of /var/lib. Additionally, I would expect any file found under a cache directory fair game to space reclamation. Granted, it might be safer to stop the snapd service before removing the files, perhaps?
This has been answered a few times, unfortunately to people (or bots) that were reusing this question to then spam, so I deleted them, so the posts are gone…
The answers boil down to: you should not have a lot of files with hardlink count 1; at most 5 in the default install. If you have more than that, it’s a bug, please let us know.
And yes you can remove them without issue; no need to stop snapd.
$ sudo ls -l /var/lib/snapd/cache \ | sed '1d' \ | cut --fields=2 --delimiter=' ' \ | grep 1 \ | wc --lines 6
Guess I don’t have a default install…?
in the time between you doing a
snap remove and next doing a download from the store, you might have things in there that take you over 5.
I just dissected a IoT gateway with a 2G memory. We lost contact with it because it ran out of memory and about 1/4 of the total memory used was by the 6 cache files in /var/snapd/cache. The “core” update the 7th of April failed and the lack of memory killed the other services (inculding a service to keep the modem connected to a 4G network).
I’d like to avoid this happening again. Is there a way to limit this cache either by memory usage or amount of files (maybe down to just 2)?