You are not logged in.

#1 2017-02-21 21:07:13

mcloaked
Member
From: Yorkshire, UK
Registered: 2012-02-02
Posts: 1,238

Deleting packages installed but no longer in repos

Does anyone know of a method using a script to get a list of packages that are installed but no longer in the main repos?  It is easy enough to get a list of orphans but the list is purely those packages that were originally dependencies of another package at the time of install, but may still be valid and needed packages that are currently in the repos.  Some on the list generated by pacman -Qdt will no longer be in the repos. It would be nice to be able to generate a list without having to manually go through the output from pacman -Qdt to check which can be uninstalled.

Any script experts know how this could be done?

Last edited by mcloaked (2017-02-21 22:37:00)


Mike C

Online

#2 2017-02-21 21:16:48

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: Deleting packages installed but no longer in repos

I'm a bit confused by this phrase:

mcloaked wrote:

packages that were originally dependencies of another package at the time of install, but may still be valid and needed packages that are currently in the repos.

But anyway, have a look at...

pacman(8) wrote:

QUERY OPTIONS
-m, --foreign
Restrict or filter output to packages that were not found in the sync database(s). Typically these are packages that were downloaded manually and installed with --upgrade.

As I haven't entirely understood the goals, I'm not very sure this is what you need, but in any case I would go with -Qmdt for a start.

Last edited by ayekat (2017-02-21 21:17:23)


pkgshackscfgblag

Offline

#3 2017-02-21 21:23:44

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,772

Re: Deleting packages installed but no longer in repos

pacaur does a nice job of reporting installed AUR packages that have gone missing


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#4 2017-02-21 21:33:40

mcloaked
Member
From: Yorkshire, UK
Registered: 2012-02-02
Posts: 1,238

Re: Deleting packages installed but no longer in repos

ayekat: thank you - and yes adding the -m flag does seem to give a list of packages on the system that are no longer in the repos and which presumably should be uninstalled.  The reason I was looking at this is because periodically it is worth going through the packages in the system, and cleaning up (i.e. uninstalling) old packages that are no longer used but were not removed during regular updates, particularly for major package upgrades such as the transition from kde4 to plasma. I wasn't aware of the -m flag but it is clearly useful.  Sometimes of course there are a set of aur packages too that included deps from the aur that are no longer needed to but I guess that will be a separate issue. So thank you ewaller for the pacaur command hint too.


Mike C

Online

#5 2017-02-21 21:43:31

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: Deleting packages installed but no longer in repos

So prior to posting you did not check pacman's man page, the pacman wiki page, or even stumble upon a very recent thread with a nearly identical title?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2017-02-21 21:51:07

mcloaked
Member
From: Yorkshire, UK
Registered: 2012-02-02
Posts: 1,238

Re: Deleting packages installed but no longer in repos

Trilby wrote:

So prior to posting you did not check pacman's man page, the pacman wiki page, or even stumble upon a very recent thread with a nearly identical title?

OK I accept knuckles as rapped. To make up for that here is a one line command that could then be used to generate a list of those packages that I could remove:

$ echo $(pacman -Qmdt | grep -Eo '^[^ ]+' )

Piping the output to pacman -R would then be an easy way to uninstall the dead packages? ( By the way unless I missed something the wiki entry at https://wiki.archlinux.org/index.php/pacman does not refer to the -m flag)

The following command seems to do the trick to uninstall packages in the system that are not in the repos:

# pacman -R $(echo $(pacman -Qmdt | grep -Eo '^[^ ]+' ) )

Referring to the thread linked by Trilby, the pacman -Qm command lists additional packages that are no longer in the repos but some of those are manually installed aur packages - so this will flag additional packages that should be removed but more careful use of bash/scripts would be needed to exclude aur packages from a list using this command that should also be removed.

Last edited by mcloaked (2017-02-21 22:38:44)


Mike C

Online

#7 2017-02-21 22:41:22

Awebb
Member
Registered: 2010-05-06
Posts: 6,286

Re: Deleting packages installed but no longer in repos

Add a q after the Q and you can scrap the pipe.

Offline

#8 2017-02-21 22:43:03

mcloaked
Member
From: Yorkshire, UK
Registered: 2012-02-02
Posts: 1,238

Re: Deleting packages installed but no longer in repos

Awebb wrote:

Add a q after the Q and you can scrap the pipe.

Yes - excellent - thank you.


Mike C

Online

#9 2017-02-21 23:35:30

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: Deleting packages installed but no longer in repos

And get rid of the echo:

pacman -R $(pacman -Qmdtq)

You may also want to consider additional flags with the -R.  I generally use -Rsn, though 's' may or may not be good here.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#10 2017-02-22 08:42:10

mcloaked
Member
From: Yorkshire, UK
Registered: 2012-02-02
Posts: 1,238

Re: Deleting packages installed but no longer in repos

Trilby wrote:

And get rid of the echo:

pacman -R $(pacman -Qmdtq)

You may also want to consider additional flags with the -R.  I generally use -Rsn, though 's' may or may not be good here.

Yes, that looks like being optimal, and useful with the additional flags when appropriate - I plan to run this periodically now on my systems, and then follow it with:

pacman -Qmq

to get a list of any additional non-orphaned packages as well as aur manually installed packages - and then remove the non-aur packages in the list. I will also try to fathom out a way to do that in a script, and will post if I find a nice solution to make the task easier.


Mike C

Online

Board footer

Powered by FluxBB