Skip to content

Instantly share code, notes, and snippets.

@soychicka
Forked from rumansaleem/clean-up-arch-linux.md
Last active November 19, 2022 20:06
Show Gist options
  • Save soychicka/4d55ea9669392a165486c359144087da to your computer and use it in GitHub Desktop.
Save soychicka/4d55ea9669392a165486c359144087da to your computer and use it in GitHub Desktop.
Instructions to clean up Arch Linux (Manjaro)

Contents

  • Clean pkg cache
  • Remove unused packages (orphans)
  • Clean cache in /home
  • remove old config files
  • Find and Remove
    • duplicates
    • empty files
    • empty directories
    • broken symlinks
  • Find Large files

1 Clean pkg cache

List packages

ls /var/cache/pacman/pkg/ | less 

Remove all pkg except those installed

sudo pacman -Sc 

Remove all files

sudo pacman -Scc

Download manually from archive.

Automatically remove

sudo pacman -S pacman-contrib

Remove

paccache -r

Systemd timer create file in /etc/systemd/system/paccache.timer with the following contents

[Unit]
Description=Clean-up old pacman pkg cache

[Timer]
OnCalendar=monthly
Persistent=true

[Install]
WantedBy=multi-user.target

Enable by sudo systemctl start paccache.timer

Pacman post-transaction hook

2 remove unused packages

List unused

sudo pacman -Qtdq

Remove unused

sudo pacman -R $(pacman -Qtdq)

3 Clean home cache

cache is located in ~/.cache

4 Config Files

stored in ~/.config/

5 Find and remove

install rmlint package sudo pacman -S rm lint.

from https://forum.manjaro.org/t/cleaning-up-and-freeing-disk-space/6703/31?page=2

Using -mtime does:

find ~/.cache -depth -type f -mtime +100 -delete While we’re at it, here’s my housekeeping stuff. I keep it in a shell script that can be run all at once for convenience, but it’s also around for reference if I only want to perform a specific task.

Vacuum journals

sudo journalctl --vacuum-size=500M && sudo journalctl --vacuum-time=7d

Remove all uninstalled packages

sudo paccache -rvuk0

Remove old installed packages, leave 3

sudo paccache -rvk3

Clean yay cache

yay -Sc -a

Clean pamac build cache

pamac clean -bv

Clean temporary build files

rm -rf ~/{.bundle,.cargo,.cmake,.dotnet,.electron,.electron-gyp,.gem,.gradle,.lazarus,.node-gyp,.npm,.nuget,.nvm,.racket,.rustup,.stack,.yarn} || true rm -rf ~/.cache/{electron,electron-builder,go-build,node-gyp,pip,yarn} || true sudo rm -rf ~/go || true

Find files not owned by any package

sudo lostfiles I have a Pacman hook for detecting orphans:

/etc/pacman.d/hooks/orphans.hook [Trigger] Operation = Install Operation = Upgrade Operation = Remove Type = Package Target = *

[Action] Description = Checking for orphaned packages... When = PostTransaction Exec = /usr/bin/bash -c "/usr/bin/pacman -Qtd || /usr/bin/echo '=> No orphans found.'"

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