Maclean - A script to automate some (safe) cleaning

Maclean is a straight-forward script that includes many possible actions to reclaim disk space; particularly from caches, logs, and user $HOME.

Defaults to step-by-step prompting - only accept actions you are comfortable with.

Optionally include your own set of paths, clean only desired grouping (‘containers’, ‘developer’, ‘basic’, etc), or automatically start and affirm all cleanings.

And is now also available as maclean-git in the AUR;

What does it clean exactly?

Click here for an index of all cleaning operations
Operation Clean Remove Paths Notes
User-defined Junk :check_mark: ~/.adobe , ~/.macromedia Default targets listed. Edit or add to the array in the script.
Thumbnail cache :check_mark: ~/.cache/thumbnails Keep anything accessed within last 2 weeks.
$HOME cache :check_mark: ~/.cache Keep select directories*. Keep anything accessed within last 2 weeks.
Journal logs :check_mark: Keep logs from the last 2 weeks.
Coredumps :check_mark: /var/lib/systemd/coredump Removal.
SNAP data :check_mark: :check_mark: ~/.snap , ~/snap , /var/lib/snapd Cleaning if installed. Removal if uninstalled.
Flatpak data :check_mark: :check_mark: ~/.var/app , ~/.local/share/flatpak , /var/lib/flatpak , /var/tmp/flatpak-cache* Cleaning if installed. Removal if uninstalled.
Docker data :check_mark: :check_mark: /var/lib/docker Cleaning if installed. Removal if uninstalled.
Go data :check_mark: :check_mark: ~/go , ~/.cache/go-build Cleaning if installed. Removal if uninstalled.
Java cache :check_mark: ~/.java/deployment/cache , ~/.config/java/deployment/cache Removal.
Corepack data :check_mark: :check_mark: ~/.cache/node/corepack Cleaning if installed. Removal if uninstalled.
npm cache :check_mark: :check_mark: ~/.npm Cleaning if installed. Removal if uninstalled.
pnpm cache :check_mark: :check_mark: ~/.local/share/pnpm , ~/.cache/pnpm Cleaning if installed. Removal if uninstalled.
yarn cache :check_mark: :check_mark: ~/.yarn Cleaning if installed. Removal if uninstalled.
rustup data :check_mark: ~/.rustup Removal.
rust crates :check_mark: :check_mark: ~/.cargo Cleaning if installed. Removal if uninstalled.
ruby gems :check_mark: :check_mark: ~/.local/share/gem Cleaning if installed. Removal if uninstalled.
pip cache :check_mark: :check_mark: ~/.cache/pip Cleaning if installed. Removal if uninstalled.
pkgfile cache :check_mark: /var/cache/pkgfile Removal if uninstalled.
PackageKit cache :check_mark: :check_mark: /var/cache/PackageKit , /var/lib/PackageKit Cleaning if installed. Removal if uninstalled.
Pamac data :check_mark: /var/tmp/pamac , /var/tmp/pamac-build-“$USER” Removal if uninstalled.
AUR Helper cache :check_mark: :check_mark: Loop through supported AUR Helpers to invoke their cleaning flags.
Package cache :check_mark: /var/cache/pacman/pkg Remove all uninstalled cache, unused repos, and/or all but 2 latest installed cache.
Orphan Packages :check_mark: /var/cache/pacman/pkg Remove all orphan packages. Please review before confirmation.
pacnew+pacsave files ⁿ/ₐ ⁿ/ₐ Warning Only. Use pacdiff to manage.

* Cache Cleanings of $HOME conveniently omit certain directories; mainly those associated with package managers, AUR helpers, browsers or chroots.

As always feedback is welcome.

Something like this really should b e a GUI app.

Nice, reclaimed 2G of space, cheers!

Thanks. 11,4 GB recovered

A config file would be neat to configure it once and afterwards just run maclean :slight_smile:
I would be interested which of the mentioned parameters in the README relate to which table entry. That’s not exactly clear to me

There actually is a config file that should have been created on first run at ~/.config/maclean/maclean.conf, but currently its only job is to set the ‘Junk’ directories.
I do have vague plans to expand it in the future.

Ah, fair point. It can somewhat be inferred but I may create an extra column for the table .. possibly inserting some sort of similar index into the script’s help or maybe an extra flag for it.

I rather find things the other way around - I would like something, especially a utility with a handful of particular functions, to be CLI first. Its always quite annoying if you can perform some function only using the GUI - how will you do that from the TTY, or use that tool programmatically (such as part of an alias, fired automatically at login, or employed in your own script, etc)?

Maybe one day there will at least be something like yad dialogs. Maybe GMaclean like GUFW for UFW .. or maybe just an embedded option like maclean -g or something like that. One day.

Thanks for this cool tool , dude … :+1:

Amazing script managed to liberate over 10GB across my laptop and desktop

Thx @cscs for this really useful script!
May I suggest adding ! -path ‘/protonfixes/’ in the section for ignored directories…

…to keep the upscaler files.

You may .. and its done. :grin:

(update at the gitlab source)

Holy shit I just cleaned out 34.63 GiB of data. What the hell. 18.35 GiB in the pacman cache, 7.59 GiB in the AUR helper cache, 2.74 GiB in the rust cargo cache, and 5.76 GiB in $HOME cache for files not accessed for 2 weeks.

I had no idea I had that much shit piled up.

Wow, it removed nearly 11GB of junk, 9 of them being “cache of uninstalled packages and unused repositories”:

maclean log
Clean $HOME cache of files not accessed for 2 weeks (y/N)? y
Done
Recovered 1.59GiB

Clean thumbnail cache of files not accessed for 2 weeks (y/N)? y
Done
Recovered 8MiB

Clean journal of any logs older than 2 weeks (y/N)? y
Done
Recovered 0B

Clean up ALL Flatpak application data (y/N)? n
Skipped

Clean AUR Helper cache of ALL diff and package build files (y/N)? y
Done
Recovered 232MiB

Clean cache of uninstalled packages and unused repositories (y/N)? y
[sudo] password for root: 
Done
Recovered 9.05GiB

Clean out pacman sandbox and interrupted download directories (y/N)? y

The following will be deleted:
/var/cache/pacman/pkg/download-l1VSkl

Continue with removal (y/N)? y
Done
Recovered 0B

Attention! Manual intervention required for the following files: 
/etc/opensnitchd/system-fw.json.pacnew

Total Recovered: 10.88GiB

I hope it did not do any harm :smile: The only thing I was really unsure about was the “Clean up ALL Flatpak application data (y/N)?”, because it sounds like it will delete all flatkpaks (which I’m sure it woudln’t do). Maybe the question could tell you a little more what this step will actually do.

It will delete any flatpak paths manually - and this is only offered if no flatpak command is found (while the paths are).

This is also illuminated on the table at the project and was copied to the opening post here .. but it does need updating;

Open source this please

???

How is it not?

Thanks cscs.
Runs well. I’ve got almost 13 Gib free.

@cscs Have you thought about adding Docker (build) cleanup as well?

I cleaned around 90 GiB a few days ago

Maybe poster hates beer?

Hm. Not really. But good suggestion. Now I guess I have to generate a bunch of docker data. :sob:

Heh. There actually may be something to that. Though I dont think it was what that poster was referring to. :sweat_smile:
I think under the strictest of terms some of my joke licenses are not considered legitimately open enough. I forget which exactly .. but I recall one, and maybe it was beerware but maybe it was cat-supremacy .. that did cause some (not my) package to be removed from the debian or fedora repos until it applied a different license. I might consider replacing any of the joke ones with a proper license if something becomes popular enough for it to matter.

Thank you this will help clean up the files that I no longer really need after everything has been installed.

Btw, in case someone prefers an AUR package over manual installation: