Maclean - A script to automate some (safe) cleaning

Another day another script. :slight_smile:

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.

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.
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.
npm cache :check_mark: :check_mark: ~/.npm Cleaning if installed. Removal if uninstalled.
yarn cache :check_mark: :check_mark: ~/.yarn Cleaning if installed. Removal if uninstalled.
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.

10 Likes

I don’t think you wrote a single word of this post but I remember desperately needing things like this (ccleaner; otc) in Windows days..
..but Linux? Can’t hurt.

I think, from this list, that basic pacman/yay cleanup commands account for 60% of this list.
The other 40%?
Would love to get a Flatpak-scrubbing command and java-specific command and I’m not sure if the in-house stuff does the coredump data?

Interesting tool all the same. I just ran, tonight, my monthly Idiots Maint Guide stuff. Be interested in how much more useless stuff i could scrub. McCleans an experiment for another night.

Huh? Why?

Part of the reason I made it on a lark however many moons ago was because the majority of similarly categorized tools (like bleachbit) had some nasty habits.

Not sure what these numbers are meant for/from (total filesize for deletion?.. amount of code in the script?.. number of entries in the index table?), but in any case the only metric in which the pacman/aur-helper section accounts for the majority may be in total space saved - but that being a dependent scenario. IE - depends on the system. In one otherwise very clean but the cache was never tended to - then it would likely account for the majority of space recovered.

Wherever possible the script prefers tools pertinent to the task.
For example - pacman cache is cleaned using paccache .. not some rm ... command.
Flatpak, java, and coredumps are all covered.

Let me know how you find it or if you have some other suggestions.

Just while typing this I realize one possible addition could be an accounting of total space recovered. As of now no such function exists .. one would ostensibly observe the status before and after. If only by looking at the bottom part of dolphin, for example.

2 Likes

I have been using Arch for over five years and rarely needed more than a pacman -Scc to clean the package cache. The cache folders are controlled by the applications that use them and the logs are capped by the journal service (unless there is a problem with something and simply cleaning them does not solve problems that would cause unhealthy growth in cache folders and logs). I guess there may be a use for some of this maintenance, but once you leave Windows behind, you can safely drop the obsessive old habit of cleaning up after the operating system.

2 Likes

I understand the sentiment, I really do ..

But whether someone is a developer using multiple software management sources, or someone has simply forgotten that coredumps can grow quite large, or for some of us that multiples of these things can be true - there can be value, if only in time saved, by simply having to run fewer commands.

Furthermore not everyone exists in a scenario where space is something negligible.

If you like you can think of this more as a collection of aliases for the various cleaning functions that would be pertinent to a given system and/or user $HOME.

( If you have yay then yay cleanings will be triggered .. if you used rust crates then the things for that .. and so on.. )

It may also be noted that a lot of the functions outside of what you may be familiar with deal with errant directories that may be leftovers in $HOME. For which there is no encompassing cleaning available.

The proof could also be in the pudding - I wonder if you would or would not find some superfluous weight, knowing as we do that the ‘regular’ maintenance has been performed.

2 Likes

My use case is fairly simple. I build Arch based spins and have long ago settled on my preferred software choices.. I can appreciate others have more complex computing needs and may welcome some assistance in cleaning tools. Rock on! :smiling_face_with_sunglasses:

1 Like

There’s always something satisfying about a before and after result, particularly when it has made a difference. As a means of challenge, one could even do their typical cleaning tasks (eg: yay -Yc, paccache, etc), then run your Maclean script to see the difference beyond the typical.

2 Likes

I have bookmarked your page. Really very nice tools that can help most users. And also me

BTW, very nice to have you on board :enos:

6 Likes

Thanks for this. I was able to recover more than 10GB. :sweat_smile:

5 Likes

It wasn’t meant offenive. It was like smooth ad copy: it made me interested.

My numbers were not clear. If you do a series of cleanup commands like paccache or yay -Rns packagex, for instance, I think (erroneously?) that Endeavour itself does 60% of what McClean’s does. Or not?

Thanks for your fantastic reply.

1 Like

wow. nice.

I think projects like this are great for one when they are learning. However I looked at the code and for Me there is a lot of BLOAT. I don’t think users should run these types of tools without first knowing how to do it manually. Knowing and understanding how the tools work are what make them affective. People blindly running “Cleaner” tools end up removing things they didn’t mean to because they didn’t know what they were doing to start with.

1 Like

I mostly agree.

Though in the case of maclean the only possible ‘gotchya’ is probably the orphans .. if you somehow had orphans you wouldnt want removed.
I dont think anyone who does not know what they are doing should blindly do just about anything - but that would apply to rm or pacman as well as maclean.
Considerations about feasibility and the like I think were mostly answered above.

I am interested in what you would consider bloat?
Each path/function/section is self-contained and does what it is supposed to do with some minor additions in the way of things like text output and prompting.

Taking the example of pacman cache ..

_mc_pacmancache() {
    if command -v paccache >/dev/null 2>&1 && [[ $(LANG=C paccache -dk2 | awk 'NR==1 {print $2; exit}') != "no" ]]; then
        echo -ne "\nClean installed package cache of all but 2 latest instances (y/N)? "

        read -r response
        if [[ $response =~ ^(yes|y|Y|Yes)$ ]]; then
            paccache -rvk2 ;
            echo "Done"
        else
            echo "Skipped"
        fi
    fi
}

Line 1 - Check for existence of paccache tool and see if there is any removable cache.
Line 2 - Print the prompt
Line 3 - Blank
Line 4 - Read prompt response
Line 5 - if ‘yes’ then
Line 6 - Do paccache action
Line 7 - Print ‘Done’
Line 8 - Else
Line 9 - Print ‘Skipped’
Line 10-11 - End ‘if’ statements

What exactly would we consider bloat and remove from this?
I guess there is a blank line..

1 Like

I’ll look later when I get a chance. There were things for cleaning/clearing that I don’t personally need as I don’t use those programs / or maybe I have different setting usage for some area’s. I am not calling it bloat as its big and bloaty for the Average person only for my specific use case’s.

If it only included the things I personally need to have cleaned it wouldnt be a very effective script for public consumption.
Things like SNAP cleaning is not included because I use SNAPs. Same for the pamac bits. etcetera. :wink:

4 Likes

I appreciate the spirit in which you came and shared your efforts here @cscs, as well as the numerous other things you’ve shared recently. I think that’s a really good thing.

Sometimes a community can miss the point, and fail to appreciate the effort and goodwill :hugs:

5 Likes

Nice clip.
Though I dont think I am too close to going full super villain.
Or maybe thats just what I want you to think (bwahahahaha).

2 Likes


If I could pick and choose which of these many variables I could clean, it would be ideal. It’s an impressive amt of categories and I respect the creator looked for errant debris under every rock since I hate clutter.
I am going to try it though this weekend.
@cscs Install directions were very clear, thank you. How would I remove it after I’ve used it?

2 Likes

You can, somewhat imprecisely, by selecting one of the categories through the flags;

 Extra Options:
   -h     Print this Help
   -j     Clean only the junk directories
   -d     Clean only the developer directories
   -c     Clean only the container directories
   -b     Clean only the few basic directories
   -a     Automatically affirm all Cleanings

Just delete the script.

It creates/installs nothing aside from itself.

(Though this may change in upcoming versions .. I think I will move out the user-defined ‘Junk’ array [and possibly some other things] into a conf file under ~/.config/maclean)

1 Like

ok, the flags correspond with the list, I get it. Thank you.

2 Likes