Maclean - A script to automate some (safe) cleaning

how much did i freed my space? as i saw the comments of other users, they have reported that their 3gb, or 30 gb or such they have freed. but mine shows nothing.i dont believe i did any wrong

Please post text, not screenshots.

as you can see from screenshot, there is no text, so what to even paste?

So a new 0.1 version of maclean is up!

Those using the AUR package should get an update automatically.

And this may be a good time for me to revisit maintainership or co-maintainership @cyb3rko :slight_smile:.

Those not using the AUR package will of course need to get it from the project page again.


Whats new ?

Depending on the user and their habits you may not notice much.

The main tool extensions include new docker support and the function related to yarn has been broadened slightly.

If little changed then why is it a major update?

Significant effort was put in to trying to make sure that various parts of the script are safer and more secure.

It required script-wide changes and custom wrappers for sudo and rm as well as sanitation of paths.

This includes the possibly lesser-known or lesser-used ~/.config/maclean/maclean.conf file that allows setting custom cleaning paths. While it already contained safe defaults and only ever used a simple rm (no sudo) it has been made even more resilient by actively disallowing not only paths outside of $HOME but also important paths like $XDG_DATA_HOME and $XDG_CONFIG_HOME as well as stripping possibly dangerous characters and strings.

All together this means now maclean should be just that much safer to use even in contexts of possible misconfiguration, system instability, or malicious activity.

It seems your original example was hanged but I could not see why?

The script has changed though so can you please use the latest version?

You may prefer the AUR package as it will automatically get deployed, and into $PATH, as well as receive updates.

I really think that should be a1.0 by now :slight_smile:

It did not used to have any version really .. but we have to start somewhere and I decided that should be below an actual 1.0 so 0.1 seemed reasonable.

I dunno. They might go up relatively fast after now.

Or maybe we will see 1.0 in like 2030. :sweat_smile:

Don’t be that person with the always-less-than-v1-apps, please :grinning_face_with_smiling_eyes: maclean is so cool, stable and useful, I think it has been 1.0 since the beginning :grin:

PS: maybe add this to maclean? sudo journalctl --vacuum-time=4weeks?

It does that already.. well, 2weeks, anyways.

Or are we saying it should be longer?

Wasn’t aware of that, my 0.0.1 version seems not to do that, yet :grin:

maclean -h    

 maclean

 A script to automate some relatively safe cleaning activities

 Usage: maclean [options]

 Extra Options:
   -h     Print this Help
   -p     Clean only the pkg directories
   -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 start and affirm all Cleanings
─> a maclean run @ hc4a
Clean $HOME cache of files not accessed for 2 weeks (y/N)? y
Done
Recovered 8MiB

Clean thumbnail cache of files not accessed for 2 weeks (y/N)? n
Skipped

Clean up ALL existing coredumps of crashes (y/N)? n
Skipped

Clean up ALL Flatpak application data (y/N)? y
[sudo] password for root: 
Done
Recovered 0B

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

Clean cache of uninstalled packages and unused repositories (y/N)? y
Done
Recovered 0B

Total Recovered: 8MiB

Hm… :thinking: I don’t really have an answer to that :sweat_smile:

Looking into the code, I see

## Journal Logs ##

_mc_journlogs() {
    if [[ $(LANG=C journalctl --until=-2w | awk 'NR==1 {print $2; exit}') != "No" ]]; then
        echo -ne "\nClean journal of any logs older than 2 weeks (y/N)? "

        read -r response
        if [[ $response =~ ^(yes|y|Y|Yes)$ ]]; then
            unset _mc_quicksums _mc_quicksums2
            _mc_calcfir /var/log/journal >/dev/null 2>&1
            journalctl --vacuum-time=2weeks >/dev/null 2>&1
            _mc_calcsec /var/log/journal >/dev/null 2>&1
            echo "Done"
            _mc_calcdif
        else
            echo "Skipped"
        fi
    fi
}

but I can’t remember ever being asked that. Will watch out for it next time.

Sure, feel free to message me here or on Matrix for the next steps.

Thx @cscs for maintaining this really nice little tool!
It is really helpful! :+1:

One question about installation: Afair, I used the download link from your GitLab page(curl -0 https…)and marked it as executable. This works fine so far but how can I change to the AUR package to receive updates automatically?

You would delete what you already downloaded, then install it from the AUR instead.

paru -S maclean-git

From then on you should be able to type maclean into the terminal to use it.

Thx @Dirge for your fast respond!

I’ve done as explained.
It works as expected.

Btw. the same procedure also works for cscs’s second tool called “sera“.

Thanks @cscs for this really nice tool.
It is really helpful :+1:

Greetings
Tony

Feature request: Before proposing cleanup of files in the .cache or thumbnails directories that have not been accessed for 2 weeks, the script should check whether the filesystem is mounted without the noatime option.

For example:

findmnt -no OPTIONS /home | grep -q noatime || ...

Since the latest release, noatime is the default for Btrfs, so access times may not be updated and the cleanup recommendation could be inaccurate.

So instead we will use modified time, which is not quite the same but better than nothing, in cases where we have a noatime mount option.

That has now been in the dev branch for a little bit which is close to merging with main. :slight_smile:

That does mean when that happens anyone using the AUR package will get it automatically. Anyone else of course has to do so manually.

For the extra adventurous you can always get things from that dev branch directly. Though of course there can be random small issues or instability there.

New to the forum and CachyOS but wanted to say thank you for this script! I had been fiddling with things trying to get the core applications to follow the system theme, and none of my modifications seemed to work… Ran the cleanup and for some reason now apps like Shelly follow the system theme lol. Cheers!

Hello @Ziege and welcome,

I am glad you found the script useful.

And now v0.2 is out. :smiling_face_with_sunglasses:

Which I hope is likewise useful.

While there are certainly more than a few updates including for reliability and safety .. the most notable change for end users may be the use of modified time during home cache check if the noatime option is found.
If interested you can see a list as well as all of the literal changes here;