11

Say I've added a repository using zypper ar. Then, I've gone and installed multiple packages from that repository, but now I want to remove all of them.

Is there a command that allows me to remove all the packages that I've installed just from that specific repository?

Brandon
  • 370
  • 1
  • 4
  • 16

3 Answers3

8

I think there is no such command. You can list packages from specific repository:

zypper search --installed-only --repo devel:tools

or all orphaned packages if you've already removed that repository:

zypper packages --orphaned

Then you could try to cut package names from the output and pass it to zypper remove if it's worth the effort.

marcin
  • 663
  • 8
  • 13
  • My openSuSE 12.3 system does not have the `--orphaned` option, but this might work: `zypper packages -i -R`: it lists the installed package in Reverse order of repository. – Jeroen Wiert Pluimers May 31 '14 at 10:57
  • 2
    `--orphaned` was added in zypper 1.9.2 (https://github.com/openSUSE/zypper/issues/34) – marcin May 31 '14 at 11:48
2

You can use a combination of zypper search, awk and xargs to remove all packages from a repository. For example:

zypper se --repo openSUSE-Tumbleweed-Debug --installed | awk '/^i(\+|\s)/ {print $3}' | xargs sudo zypper rm
sebix
  • 439
  • 6
  • 14
  • `awk '/^i(\+|\s)/ {print $3}'` to match all installed packages (i or i+) – Mesco Apr 23 '18 at 15:20
  • @Mesco zypper itself should only print installed packages when using `--installed`. – sebix Apr 24 '18 at 13:44
  • right, using `-i` or `--installed-only`. But also I've search for i and i+ at the beggining to skip first few rows (`Loading repository data...`). Maybe there are better methods, to skip first 5 rows but if you already use regex... ;) – Mesco Apr 24 '18 at 19:54
  • maybe I'm using different zypper version (1.14.4) but its man says that the order should be `se [options] [query]` so your solution didn't work. – Mesco Apr 24 '18 at 19:59
  • Ah, now I understand your concern. I updated the answer. About the search-syntax: I only use options and no query, so the order is correct I think. – sebix Apr 26 '18 at 10:03
0

This line works fine for me

zypper search --installed-only --repo yourbadrepo|awk {'print $3'}|xargs sudo zypper rm 

If you want to risk or use in a script, the -n option avoid confirm(can break deps)

  zypper search --installed-only --repo yourbadrepo|awk {'print $3'}|xargs sudo zypper -n rm 
elbarna
  • 12,050
  • 22
  • 92
  • 170