Skip to content

Instantly share code, notes, and snippets.

@4lgn
Last active April 28, 2024 12:36
Show Gist options
  • Save 4lgn/4a31df668321cf95a790fdb29615a846 to your computer and use it in GitHub Desktop.
Save 4lgn/4a31df668321cf95a790fdb29615a846 to your computer and use it in GitHub Desktop.
Arch Linux Cleanup

Arch Linux Cleanup

Basic notes and commands/scripts to help ease the cleanup process of your Arch Linux installation.

Introduction

One of the big pros of using Arch Linux is obviously the reduced bloat on your system, as you are obviously the sole proprietor of such bloat.

However, just as a large software project that gets developed on constantly, we end up with technical debt - and when using your Arch system as a daily driver, you will probably acquire a certain amount of such "bloat debt" over the years.

This small Gist serves as your guide to get rid of such bloat, cached/unused/orphaned packages, old config files, dangling docker images and what have you.

So take out an hour or two of your calendar and make yourself some coffee, and read on.

Contents

System

https://wiki.archlinux.org/title/System_maintenance#Clean_the_filesystem

Disk cleaning (large files)

The home cache

You can check the size of your home cache to get a sense of the potential savings with:

du -hs ~/.cache

Feel free to delve down into individual cache folders, as some of them are obviously very handy to keep, if you are actively using their cached data.

Old/unused configuration files

Pacman

Cleanup pacman cache

Using the paccache utility, you can easily cleanup old cached packages. The following command will cleanup all cached packages, but still keep the last version (so you can still easily downgrade a version, if your recent installation of a package broke something).

paccache -rk1

Optionally, you can also not keep any old versions (-rk0), or keep the last 3 (which is the default of paccache).

Remove unused packages (orphans)

You can list all the unused packages by:

pacman -Qtdq

Remember that you might still be using some of these packages, so I would definitely recommend checking through the list before removing these packages. Or you can just remove everything and re-install them when needed.

To remove all of these packages:

pacman -Qtdq | pacman -Rns -

Manually check through large packages

If you have the expac utility installed, you can get your top 50 largest packages easily with:

expac -HM '%m %n' | sort -h | tail -50

Check through these packages, and inspect their dependencies and which other packages depend on them by using pacman -Qi <package>.

Journal

https://wiki.archlinux.org/title/Systemd/Journal#Journal_size_limit

Applications/services

Docker

Check for dangling or old images, these can obviously take up a lot of space - make sure to double-check with your containers and Dockerfiles you are actively using, of course.

List images and their size

docker images

Automatically prune unused images

docker image prune

You can also use the -a flag to remove all images not referenced by any container:

VirtualBox

If you are using VirtualBox or other virtual machine applications such as VMWare, check for old or otherwise unused virtual machines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment