I'm trying to remove a bunch of packages that have 'abc' in it. However, I don't want to remove 'abc-def'. How can I accomplish this?
For example, how to remove every packages that have 'php' in it, except 'php-common'?
I tried adding --exclude
to the command, but it doesn't work as expected - 'php-common' was still in the deletation list.
# yum --exclude=php-common remove *php*
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package php-cli.x86_64 0:5.4.16-36.el7_1 will be erased
---> Package php-common.x86_64 0:5.4.16-36.el7_1 will be erased
---> Package php-fpm.x86_64 0:5.4.16-36.el7_1 will be erased
---> Package php-mcrypt.x86_64 0:5.4.16-3.el7 will be erased
---> Package php-mysqlnd.x86_64 0:5.4.16-36.el7_1 will be erased
---> Package php-pdo.x86_64 0:5.4.16-36.el7_1 will be erased
--> Finished Dependency Resolution
yum remove *php* !php-common
,--exclude=php-common*
and --exclude=php-common.x86_64 0:5.4.16-36.el7_1
doesn't work either.
I'm asking this because I have a huge package (~1.5 GB) that I still need and don't want to re-download it because my internet is slow.
OS: CentOS 7.
Simply prefix the package name that you want to keep with
-
. You need to add--
before the list of packages to ensure that the name of the package is not treated like an option:From the man page (under the install option):
--exclude
will exclude a package from the repositories, as it wasn't available to install, but it doesn't act on installed packages.One way to really protect your package from deinstallation is to put its name into
protected_packages
in/etc/yum.conf
, but thenyum
wouldn't process a wildcard that also matches that package.One solution:
With your specific example
php-common
, this will not really work as the dependency resolver will interfere, but if dependencies are not a problem, you can try the following:The subcommand will generate a list of installed packages, cut it to the first column, reduce it to packages containing
php
in the name and then eliminatesphp-common
from the list.╮(╯_╰)╭
I wrote a python to resolve this problem yesterday.
I hope it is useful for you and who was troubled about this problem. : - )
I noted down the development process on my blog
http://blog.j3l11234.com/2016/11/23/yum-remove-with-exclude/
here is the usage:
download link