Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
It is recommended to userpm -qa
Querying software Packages
RPM is recommended because in some cases, it is not accurate to use YUM. For example, half-installed or corrupted software, software not installed through the yum command, etc., may cause yum to fail to find the software.
Mysql > install RPM; mysql > install RPM;
# rpm -qa|grep mysqlMysql - community - the client - 8.0.26-1. El7. X86_64 mysql - community - common - 8.0.26-1. El7. X86_64 Mysql80 - community - release - el7-3. Noarch mysql - community - libs - 8.0.26-1. El7. X86_64 Mysql - community - the client - plugins - 8.0.26-1. El7. X86_64 mysql - community - server - 8.0.26-1. El7. X86_64Copy the code
The yum list does not match the package:
# yum list mysql*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Error: No matching Packages to list
Copy the code
When you install software with a package name and then only use yum to query again, it seems that wildcards are not supported.
The following test, yum List, can only be listed using the package’s full name:
# yum list installed mysql-community-server-8.0.26-1.el7.x86_64 # yum list installed mysql-community-server-8.0.26-1
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
mysql-community-server.x86_64 8.0.26-1.el7 @mysql80-community
# mysql - community - yum list server - 8.0.26-1. El7. X86_64
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
mysql-community-server.x86_64 8.0.26-1.el7 @mysql80-community
# yum list installed mysql*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Error: No matching Packages to list
# yum list mysql*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Error: No matching Packages to list
Copy the code
Uninstall all software packages containing a certain name using RPM and grep.
The following, by for I in $(RPM – qa | grep mysql); do rpm -e $i –nodeps; The done command is used to uninstall all packages containing mysql.
# rpm -qa|grep mysqlMysql - community - the client - 8.0.26-1. El7. X86_64 mysql - community - common - 8.0.26-1. El7. X86_64 Mysql80 - community - release - el7-3. Noarch mysql - community - libs - 8.0.26-1. El7. X86_64 Mysql - community - the client - plugins - 8.0.26-1. El7. X86_64 mysql - community - server - 8.0.26-1. El7. X86_64# for i in $(rpm -qa|grep mysql); do rpm -e $i --nodeps; done
# rpm -qa|grep mysql
#
Copy the code
As you can see, all mysql has been deleted.
for i in $(rpm -qa|grep mysql); do sudo yum remove -y $i; The done command is also recommended.
Yum removes all packages containing a certain name using a wildcard.
See a way to delete multiple applications with the same character name using the package name + wildcard (*) form.
Testing does allow you to uninstall more than one piece of software at a time. Details are as follows:
For example, uninstall all the software starting with mysql-
yum -y remove mysql-*
Copy the code
The uninstallation process is shown in the following screenshot:
As you can see, all mysql- has been uninstalled.
Mysql > install RPM
[root@VM_0_15_centos ~]# rpm -qa|grep mysql
mysql80-community-release-el7-3.noarch
[root@VM_0_15_centos ~]#
Copy the code
Similarly, other yum commands can use the * wildcard to find matches.
Mysql > install mysql* yum list mysql* yum list mysql* yum list mysql*
# yum list mysql*Loaded plugins: fastestmirror, Langpacks Loading mirror speeds from cached hostfile Available Packages mysql-python.x86_64 1.2.5-1.el7 OS El7 epel mysql++ -vel. X86_64 3.1.0-12.el7 epel mysql++ -vel. X86_64 3.1.0-12.el7 epel mysql++ -vel Mysql++ -connector-odbc.x86_64 3.1.0-12.el7 epel mysql-connector-java.noarch 1:5.1.25-3.el7 OS mysql-connector-odbc.x86_64 mysql++-manuals El7 epel mysql-mmm. Noarch 2.2.1-15. El7 epel mysql-mmm. Noarch 2.2.1-15 El7 epel mysql-mmm-tools. Noarch 2.2.1-15.el7 epel mysql-proxy.x86_64 El7 epel mysql-proxy-vel. X86_64 el7 epel mysql-utilities. Noarch 1.3.6-1 3.5-11.el7 epel mysqltuner. Noarch 1.7.21-1.git.4e0a8b3.el7 epel mysqltuner#
Copy the code
Wildcard characters may not be supported in YUM
Yum -y remove mysql-*, yum list mysql*, etc. Even when it can be queried using RPM, Yum will indicate that there is no package match.
# yum list mysql*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Error: No matching Packages to list
# yum list updates mysql
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Error: No matching Packages to list
# yum list installed mysql*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Error: No matching Packages to list
Copy the code
For example, in the same remove command above, even though the RPM -q query exists, it still indicates that there is no matching package.
# yum -y remove mysql-*
Loaded plugins: fastestmirror, langpacks
No Match forArgument: mysql-community-server-8.0.26-1. El7.x86_64. RPM No Packages markedfor removal
# rpm -qa|grep mysqlMysql - community - common - 8.0.26-1. El7. X86_64 mysql - community - libs - 8.0.26-1. El7. X86_64 Mysql - community - the client - plugins - 8.0.26-1. El7. X86_64 mysql - community - server - 8.0.26-1. El7. X86_64 Mysql - community - the client - 8.0.26-1. El7. X86_64 mysql80 - community - release - el7-3. Noarch#
Copy the code
Note: This problem, at least in
mysql*
Met with. The other packages are not one-for-one tested, but testedpam*
That seems ok.I wonder if it is related to executing yum Remove, installing mysql software, etc.
aboutyum list
andyum list installed
The command
These are used to list all packages contained in the YUM repository, and list all packages installed.
Specify package full name
Yum does not support wildcards, but you can specify the full name of the package after the yum list and yum list installed commands, which are the same for installed packages:
# yum list installed mysql-community-server-8.0.26-1.el7.x86_64 # yum list installed mysql-community-server-8.0.26-1
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
mysql-community-server.x86_64 8.0.26-1.el7 @mysql80-community
# mysql - community - yum list server - 8.0.26-1. El7. X86_64
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
mysql-community-server.x86_64 8.0.26-1.el7 @mysql80-community
Copy the code
yum list
,yum list installed
Lists all installable and installed packages
-
Yum List — Lists all installable packages, both installed and uninstalled.
-
Yum List Installed — Lists all installed packages.
Run the two commands directly.
Using the grep command
# yum list installed | grep mysqlX86_64 8.0.26-1. el7@mysql80-community mysql-community-client-plugins.x86_64 8.0.26-1. El7 @mysql80-community mysql-community-common.x86_64 8.0.26-1.el7 @mysql80-community mysql-community-libs.x86_64 8.0.26-1. el7@mysql80-community mysql-community-server.x86_64 8.0.26-1. el7@mysql80-community mysql80-community-release.noarch el7-3 installedCopy the code
Below, you can see, yum list | grep mysql contains yum list installed | grep mysql installed packages: