Why pacman -Ru (pacman -Qdtq) over pacman -Runs?

The issue with using “-s” is it can remove packages which are optional dependencies of other packages. The thread that inspired using this cleanup function is here if you are interested: Discussion about handling orphaned packages - #6 by BluishHumility

The “-u” does not address this issue with -s removing packages which are optional dependencies of other packages. What the -u does is allow the transaction to essentially “skip” packages which would be targets of the operation, but are required by other packages.

pacman - ArchWiki

To remove a package and its dependencies which are not required by any other installed package:

# pacman -Rs *package_name*

[…]

The above may sometimes refuse to run when removing a group which contains otherwise needed packages. In this case try:

# pacman -Rsu *package_name* 

The “n” should not be part of it either way.

REMOVE OPTIONS (APPLY TO -R)

[…]

-n, --nosave

Instructs pacman to ignore file backup designations. Normally, when a file is removed from the system, the database is checked to see if the file should be renamed with a .pacsave extension.

A pacsave is generated when the user has modified a config file (to customize it or change some settings or whatever), and then the package is removed. Most package removals do not generate a pacsave, but when they do it can be useful to keep them in case you want to reinstall the package later. I’m not saying don’t delete your pacsave files if you don’t need them, but certainly it is not advisable to delete them by default.

By the way, a couple months ago the function was updated to allow breaking the loop (if you want to cancel the operation).

It looks like you are still using the old version of the function; the new one looks like this:

# Cleanup local orphaned packages
function cleanup
    while pacman -Qdtq
        sudo pacman -R (pacman -Qdtq)
        if test "$status" -eq 1
           break
        end
    end
end
8 Likes