Mass delete your cached files!

decache


Have you ever thought to yourself:
“Gosh dang it, all these .zig-cache directories are taking up so much space on my disk, but I have so many projects it would take AGES to clean them all up! What ever could I do?”

decache lets you easily clean up all directories that match a pattern, such as for example .zig-cache/o/. Filtering by minimum age is also supported, with more planned!

It was very enjoyable going through the process of seeing a problem I’m having to a full working solution. They weren’t lying when they said it feels great! I got to learn a little bit about how the filesystem works on linux, and a LOT about how various utilities format their --help messages and parse their arguments.

I’ve freed up over 120GB (!!!) of cached zig and rust files from my disk, which is a LOT given that my laptop has only 512GB of storage. I wish I had a screenshot to attach, but I sadly closed the terminal before I thought to take one :​(


Examples

Delete all .zig-cache/ directories in the ~/Projects folder, and print how much space was freed:

decache --summary ~/Projects .zig-cache/

Delete all rust build outputs, and print what’s being deleted:

decache --verbose ~/Projects target/debug/ target/release/

Actually hold on a sec, make sure it IS only rust stuff that’s gonna be deleted:

decache --dry-run ~/Projects target/debug/ target/release/

Supported Zig versions

Built with zig 0.16.0.
Newer versions might also compile but are untested.

8 Likes

yesss!!!

you could probably add a “just for you!” or something, anyways thanks for the tool


it’s just a funny timing, today I was just thinking about making the same thing

1 Like

I’m far from the first person solving this exact problem lol.
When writing the title of this post discourse identified this post form a couple of months ago as being similar to mine.

Not sure what you mead by this?

1 Like

your post looks like a commercial ad, so “[product name] is the solution just for you!” is a funny stretch

Ah damn, now I wish I committed to the bit more!

one step closer to having a marketing department for Zig!

1 Like

I’m going to need some informercial vid now

This is a better solution than my scorched earth solution of just blindly nuking absolutely everything with a naive Bash function.

zigclean () {
  find "$HOME/code/zig" -type d -name '.zig-cache' -rm -rf {} +
  rm -rf "$XDG_CACHE_HOME/zig"
}
2 Likes

If it has yet to brick your system, can you really call it a bad solution?

2 Likes

Nothing against OP, but I think I might trust your version more. I can understand what it does much faster.

1 Like

There are definitely some gaps in the script that can easily strip someone up

$ echo "$XDG_CACHE_HOME/zig"
/zig

If this feature is built-in to Zig, that would be great.

1 Like

I believe cache gc was planned at some point.

Oh, this is most definitely a “my system only” script, I am not recommending anyone use it. The point was to show what a terrible method that I have been using, not sharing a script for others to use.

This tool has freed up over 60 GB of disk space for me, it seems that I really need it.

3 Likes