I was given access to a server with 50+ php rpms installed. I\'m trying to remove them all.
Basically, I\'m trying to combine these two commands:
rpm -qa
yum
List and remove the indicated packages and all their dependencies, but with a y/N
confirmation:
yum remove 'php*'
To bypass the confirmation, replace yum
with yum -y
.
rpm
This section builds upon the answers by twalburg and Ricardo.
List which RPMs are installed:
rpm -qa 'php*'
rpm -qa | grep '^php' # Alternative listing.
List which RPMs which will be erased, without actually erasing them:
rpm -e --test -vv $(rpm -qa 'php*') 2>&1 | grep '^D: erase:'
On Amazon Linux, you may need to use grep '^D: ========== ---'
instead.
If the relevant RPMs are not listed by the command above, investigate errors:
rpm -e --test -vv $(rpm -qa 'php*')
Erase these RPMs:
rpm -e $(rpm -qa 'php*')
Confirm the erasure:
rpm -qa 'php*'
to list:
rpm -qa | grep 'php'
to remove instaled listed and filtrated:
rpm -e $(rpm -qa |grep 'php')
The usual tool for this job is xargs:
rpm -qa | grep 'php' | xargs rpm -e
This will call rpm -e
with all packages named in the standard input of xargs
as arguments.
Another option is to use the output of rpm -qa | grep ...
in the rpm --erase
command directly:
rpm --erase `rpm -qa | grep php`
Maybe not for the php
case you're citing, but the xargs
approach might possibly run into issues if it decides to split the list into several invocations of rpm -e
and the first list contains packages that are dependencies of packages in subsequent lists. Of course, if you're removing that many packages all at once, you might have other things that you need to consider...
I had this today. Using --justdb and --noscripts rpm parameters wasn't sufficient without the --allmatches, and that's it.
[root@localhost ~]# rpm -ev --allmatches --justdb <the-package-name>
https://mcvictech.blogspot.com/2011/10/rpm-error-specifies-multiple-packages.html