Maclean - a small script to automate (safe) cleaning functions

I dont normally like these kinds of utilities… so I figured I would make one. :innocent:

Its up on gitlab:

Example run:

Its still early days.
Every action prompts the user first, with default response being negative.
I am still compiling all of the ‘cleaning actions’ it should take.

It should loop through any number of AUR helpers installed.
(includes: pacaur, pamac, paru, pikaur, trizen, yay)

SNAP/Flatpak cleanings are also included to the best of my knowledge, but I dont use either.
(and these will only be presented if snap is running or flatpak is installed)

As always feedback is welcome.
Let me know if its doing something dumb or if there is something you think should be included.


18 find ~/.cache/thumbnails -mindepth 1 -type f -mtime +14 ;

I can’t bash script my way out of a wet paper bag, but is that line missing a -delete?

1 Like

I’m just wondering why the thumbnail cache is cleaned separately using the mtime when immediately afterwards the home cache (which contains the thumbnail directories) is cleaned using the atime. Wouldn’t it be better to use atime on the thumbnails as well? If using mtime, thumbnails which are accessed on a regular (such as daily) basis will still be deleted every 2 weeks, requiring the writing of new, identical thumbnails to the disk.

Also, it might be wise to omit the Firefox cache folder from cleaning as Firefox manages its own cache. This is what I’ve been using for quite a few years in my own cleanup script which runs every startup:

find ~/.cache/ -depth -type f -not -path "*mozilla/firefox*" -atime +45 -delete

1 Like

Thats what I get for doing a last minute check, but not checking what I did during said check.

I agree I should probably use access for both.
The reasoning for keeping them separate was to … well, keep it separate … so that one wishing to only delete the thumbnails (which on its own can grow rather large over time) without necessarily wanting to purge the whole cache of anything ‘old’.
I think I might adopt your attitude towards the firefox cache … possibly adding others to the omission (chromium, thunderbird).

1 Like

Nice idea. I like the separation of jobs.

My cleaner does:

pacman -Sc
pamac clean --build-files
paccache -rvuk0
paru --clean
flatpak uninstall --unused
journalctl --vacuum-time-12h
journalctl --flush --rotate

So I’m interested to mix and match a bit.

1 Like

I see where you’re coming from. Maybe just changing the menu option to “Clean thumbnail cache of ALL files older than 2 weeks (y/N)?” would prevent any confusion.

Overall, the script is a very good idea. It has always irritated me ever since I started using GNU/Linux in 2005 that there is no automated function to clean old, unused files from the cache.

I changed and added some things, due in part to the comments here.
@scotty65 @Takakage

Of note: Incorporated fixes from above, new prompt for orphans, and a check/warning of pacnews.

Update again. Now with -h (help) and -a (automatic ‘yes’ mode) options.
Original mode of ‘just run and get prompted’ still intact.

And a note on the name…
Yes its Manjaro+clean but as usual it has multiple interpretations…
Its also one letter away from a certain common cleaning product, and phonetically similar to certain regal figure of yesteryear.

Cheers until next time. :slight_smile:

More updates.
Put in a check to disallow running as root, pacnew warning now only fires if you have them, and added a snazzy icon. :wink:

ToDo: Find a new extra-permissive (joke?) license.


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

Clean HOME cache of files not accessed for 2 weeks (y/N)? 

Clean journal of all logs older than 2 weeks (y/N)? 
Vacuuming done, freed 0B of archived journals from /var/log/journal.
Vacuuming done, freed 0B of archived journals from /run/log/journal.
Vacuuming done, freed 0B of archived journals from /var/log/journal/d24beb85f3334ebb96b273459eede537.

Clean old and unused Flatpak REFs (y/N)? 
Nothing unused to uninstall
Fehler: Error opening directory '/home/weingeist/.var/app': Datei oder Verzeichnis nicht gefunden

If you do not use flatpak and answer yes, the script will be cancelled.

A wonderful script, of course. Thank you for it

1 Like

Thanks. That comes from flatpak uninstall --delete-data.
This prompt only shows up if you have flatpak installed … but since flatpak fails out trying to clean if it cant find that folder … I will make this part only fire if the directory exists.
(the whole prompt only fires if flatpak is installed … but that doesnt mean you have been using it)

…And done. :slight_smile:

More updates.
Now with support for npm and pip caches.

Updates again.
Better prompt for automatic mode (gives warning, resets sudo, asks for password verify)
Even less prompting now (package cache checked before asking, ex: no prompt for uninstalled cache if there are none)
Also added some more output like “Done” and “Skipped”.
And one more thing most will not notice :wink:
(for the paranoid … its a check for ancient flash directories)

The heaviest functions still do not check prior to prompting.
I consider the load too high to do automatically (these all rely on traversing the filesystem to some degree). But this does all add up to a rather slim output if the system is clean;

$ ./maclean

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

Clean HOME cache of files not accessed for 2 weeks (y/N)? y

Clean AUR Helper cache of all build files (y/N)? n

1 Like

Whole new post because lots of updates.

All major browser caches are skipped (vivaldi, brave, chromium, chrome, ff, thunderbird)

Many internals to make it a bit faster and such.

The big one is a now -easily- configurable “junk directories” that the user can augment, at the top of the script. It replaces the previous check for ancient flash folders, which now become the default population of the junk folders.

PS. Settled on beerware license for now. Not my most favorite, but one I had not used yet. :woman_shrugging:

1 Like

Script stops with:

xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

when cleaning $HOME cache

Oo fun … we must have a funny file name in there?

Maybe you can check with a stripped version to print:

find ~/.cache -mindepth 1 -type d ! \( -readable -executable \) -prune -o ! -path */yay/* ! -path */vivaldi/* ! -path */trizen/* ! -path */pip/* ! -path */pikaur/* ! -path */paru/* ! -path */pamac/* ! -path */pacaur/* ! -path */thunderbird/* ! -path */manjaro-tools/* ! -path */mozilla/* ! -path */google-chrome/* ! -path */chromium/* ! -path */chroots/* ! -path */BraveSoftware/* -type f -atime +14 -print

Or if the output is too large you can send it to a file:

find ~/.cache -mindepth 1 -type d ! \( -readable -executable \) -prune -o ! -path */yay/* ! -path */vivaldi/* ! -path */trizen/* ! -path */pip/* ! -path */pikaur/* ! -path */paru/* ! -path */pamac/* ! -path */pacaur/* ! -path */thunderbird/* ! -path */manjaro-tools/* ! -path */mozilla/* ! -path */google-chrome/* ! -path */chromium/* ! -path */chroots/* ! -path */BraveSoftware/* -type f -atime +14 -print > myoldcachefiles.txt

And view it, ex;

less myoldcachefiles.txt

( I have of course double checked and it runs here. )

While I havent heard back from @wes33 yet…
I did make some changes to the script.
Please try the latest version and let me know how it works for you.

I like this one:

1 Like

I like to actually keep them super permissive.
Otherwise I would make sure to rant all my personal politics etc.
Though … I have been tempted by the “Be Gay Do Crimes” License, and this one:
(which stipulates you must commit no less than 3 US criminal offenses :sweat_smile:)


Then I’m glad I like doing this :point_up_2: kind of thing manually.

Because I’m too boring for that even if I did live in, or ever was even close to the US.

Violating the terms of the license should count for at least one …

I jest about using them of course though.

As I said - I like them to be permissive so that people can be/feel free with it.
(But that certainly doesnt mean I cant have fun with it … I still think I like the cat supremacy license best … the final line is something like “all others are given the above rights, albeit grudgingly”)

The new version fixes the problem

Which was a file whose path included the string:

Love’s Crushing Diamond

thanks for the quick fix; script is a great idea

Glad to hear it, and thanks for helping make an improvement :slight_smile:

Another day another handful of updates.

  • Some backend stuff (command -v and LANG=C)

  • As shown in the table below, the cache directories for pkgfile and PackageKit are now checked.**

  • The gitlab page has a fancy table now

(That looks like this)
Operation Clean Remove Paths Notes
User-defined Junk :heavy_check_mark: ~/.adobe , ~/.macromedia Default targets listed. Edit or add to the array in the script.
Thumbnail cache :heavy_check_mark: ~/.cache/thumbnails Keep anything accessed within last 2 weeks.
$HOME cache :heavy_check_mark: ~/.cache Keep select directories*. Keep anything accessed within last 2 weeks.
Journal logs :heavy_check_mark: Keep anything accessed within last 2 weeks.
SNAP data :heavy_check_mark: :heavy_check_mark: ~/.snap , ~/snap Cleaning if installed. Removal if uninstalled.
Flatpak data :heavy_check_mark: :heavy_check_mark: ~/.var/app Cleaning if installed. Removal if uninstalled.
npm cache :heavy_check_mark: :heavy_check_mark: ~/.npm Cleaning if installed. Removal if uninstalled.
pip cache :heavy_check_mark: :heavy_check_mark: ~/.cache/pip Cleaning if installed. Removal if uninstalled.
pkgfile cache :heavy_check_mark: /var/cache/pkgfile Removal if uninstalled.
PackageKit cache :heavy_check_mark: :heavy_check_mark: /var/cache/PackageKit Cleaning if installed. Removal if uninstalled.
AUR Helper cache :heavy_check_mark: :heavy_check_mark: Loop through supported AUR Helpers to invoke their cleaning flags.
Package cache :heavy_check_mark: Remove all uninstalled cache and/or remove all but 2 latest installed cache.
Orphan Packages :heavy_check_mark: Remove all orphan packages. Please review before confirmation.
pacnew+pacsave files Warning Only. Use pacdiff to manage.

** I have neither installed, but they left behind directories in /var/cache, so I expect it may be similar for others. Using either software with Arch/Manjaro is not recommended.

1 Like

Firefox cache clean shows ‘y/n’.

I’d hope for ‘y/N’ for a sane default.