Skip to content

Instantly share code, notes, and snippets.

@rumansaleem
Created May 28, 2019 08:51
Show Gist options
  • Save rumansaleem/083187292632f5a7cbb4beee82fa5031 to your computer and use it in GitHub Desktop.
Save rumansaleem/083187292632f5a7cbb4beee82fa5031 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.

@optimistic5
Copy link

@bassam-azizi
Copy link

Thank You

Copy link

ghost commented Apr 29, 2021

Thanks man

@aragon999
Copy link

To list the packages you do not need sudo:

$ pacman -Qtdq

@RuiGuilherme
Copy link

RuiGuilherme commented Jun 22, 2021

Another recommendation if you want remove large/orphans packages:
https://wiki.archlinux.org/title/Pacman/Tips_and_tricks#Listing_packages
https://wiki.archlinux.org/title/Pacman/Tips_and_tricks#Removing_unused_packages_(orphans)

Edit:
About home .cache normally there are no problems to delete this, but a good practice would not delete only the old caches?...:

# find ~/.cache/ -type f -atime +30 -delete

About home .config: If you use VSCode don't do it without careful.

@aragon999
Copy link

Another thing I find now useful is to remove the cache of all uninstalled packages using:

$ paccache -ruk0

r: Remove packages
u: specifies uninstalled packages,
k0: "keep" 0 versions

Copy link

ghost commented Dec 22, 2021

Is this really for removing unused packages sudo pacman -Qtdq? Like, There is linux-rt-manjaro
in my list of unused packages which is kernel module

@aragon999
Copy link

@cybersexurity69 linux-rt-manjaro sounds more like the real time manjaro linux kernel and not as a kernel module (https://wiki.archlinux.org/title/Unofficial_user_repositories#realtime).

What -Qtdq will do according to the man page is (-Q stands for querying the package database):

       -d, --deps
           Restrict or filter output to packages installed as dependencies. This option can be combined with -t for listing real orphans
           - packages that were installed as dependencies but are no longer required by any installed package.

       -t, --unrequired
           Restrict or filter output to print only packages neither required nor optionally required by any currently installed package.
           Specify this option twice to include packages which are optionally, but not directly, required by another package.

       -q, --quiet
           Show less information for certain query operations. This is useful when pacman’s output is processed in a script. Search will
           only show package names and not version, group, and description information; owns will only show package names instead of
           "file is owned by pkg" messages; group will only show package names and omit group names; list will only show files and omit
           package names; check will only show pairs of package names and missing files; a bare query will only show package names rather
           than names and versions.

Which means that you have not directly installed this package, but it was installed as a dependency which was later removed. So if you are sure you want to keep this package (since you use it), you can just reinstall the package: sudo pacman -S linux-rt-manjaro and it should not be shown in the list of packages which get removed.

Not sure if Manjaro in general handles things differently, such that any of the above information is not valid in that case. It should be valid for Arch itself.

@aryav-v
Copy link

aryav-v commented Jan 15, 2022

thanks for all these commands

@Abdullah-coder2013
Copy link

Thanks!

@Marc-Pierre-Barbier
Copy link

use sudo pacman -Rs $(pacman -Qtdq)
instead of sudo pacman -R $(pacman -Qtdq) otherwise you would have to run it multiple times in a row

@kelvindecosta
Copy link

Thanks!

@Fabienjulio
Copy link

Thanks!

@3llena
Copy link

3llena commented Apr 14, 2022

use sudo pacman -Rs $(pacman -Qtdq) instead of sudo pacman -R $(pacman -Qtdq) otherwise you would have to run it multiple times in a row

-Rcns

@muxina-credo
Copy link

Awesome! Thanks.

@yusufalvian16
Copy link

thank you.

@mrcodekiddie
Copy link

🥺 Thanks everyone

@mnzsss
Copy link

mnzsss commented Nov 10, 2022

thanks!

@Ser4ph4
Copy link

Ser4ph4 commented Nov 12, 2022

thanks

@FelypeInvictus
Copy link

Very useful... Thank u, bro

@viniciusgonmelo
Copy link

Does sudo pacman -R $(pacman -Qtdq) also remove config files, something like apt autoremove --purge for Debian based distros?

@Bryan2333
Copy link

Does sudo pacman -R $(pacman -Qtdq) also remove config files, something like apt autoremove --purge for Debian based distros?

Nope, see Removing packages

@venkatrahul-software-development

Thanks, very useful in maintaining arch-manjaro system clean

@rabichawila
Copy link

Thanks, Bookmarking this Gold

@FromSi
Copy link

FromSi commented Feb 21, 2024

thanks

@aragon999
Copy link

use sudo pacman -Rs $(pacman -Qtdq)
instead of sudo pacman -R $(pacman -Qtdq) otherwise you would have to run it multiple times in a row

This won't work as -s is for --search
https://archlinux.org/pacman/pacman.8.html

That is only true for sync (-S) or query (-Q) operations. For remove (-R) operations -s is for recursive. See "Remove Options" on the pacman man page.

@fastoch
Copy link

fastoch commented Apr 17, 2024

use sudo pacman -Rs $(pacman -Qtdq)
instead of sudo pacman -R $(pacman -Qtdq) otherwise you would have to run it multiple times in a row

This won't work as -s is for --search
https://archlinux.org/pacman/pacman.8.html

That is only true for sync (-S) or query (-Q) operations. For remove (-R) operations -s is for recursive. See "Remove Options" on the pacman man page.

You're right, I've removed my comment.

@PthDE
Copy link

PthDE commented May 31, 2024

Immensely informative and practical.
Thank you so much!

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