Ubuntu and CentOS find packages based on commands

  table of Contents

、 Untu Ubuntu

1.1 Step

1.2 Examples

Two, CentOS

2.1 Step

2.2 Examples

Three, summary


When using Linux, sometimes it is necessary to query which package a certain command belongs to. The following mainly introduces Ubuntu (also applicable to Linux using dpkg package management tool) and CentOS (also applicable to Linux using rpm as package manager). Command query method of software package.

、 Untu Ubuntu

1.1 Step

1. First use which to query the absolute path of the command;

2. Use dpkg to find out which package has been installed contains the path;

Simply speaking, the steps may not be understood, but you will understand if you look at the examples below.

1.2 Examples

(1) Query the package where the wget command is located, as shown below:

root@xipeng:~# which wget
/usr/bin/wget
root@xipeng:~# dpkg -S /usr/bin/wget
wget: /usr/bin/wget
root@xipeng:~#

 (2) Query the software package where the curl command is located, as shown below:

root@xipeng:~# which curl
/usr/bin/curl
root@xipeng:~# dpkg -S /usr/bin/curl
curl: /usr/bin/curl
root@xipeng:~#

The command which can query the absolute path of the current command, dpkg -S searches the file name from the installed software package.

Two, CentOS

2.1 Step

1. First use which to query the absolute path of the command;

2. Use rpm to query which package has been installed contains the path;

2.2 Examples

(1) Query the package where the wget command is located, as shown below:

[root@localhost ~]# which wget
/usr/bin/wget
[root@localhost ~]# rpm -qa --queryformat="[%{NAME} : %{INSTFILENAMES}\n]" | grep /usr/bin/wget
wget : /usr/bin/wget
[root@localhost ~]#

(2) Query the software package where the curl command is located, as shown below:

[root@localhost ~]# which curl
/usr/bin/curl
[root@localhost ~]# rpm -qa --queryformat="[%{NAME} : %{INSTFILENAMES}\n]" | grep /usr/bin/curl
curl : /usr/bin/curl
[root@localhost ~]#

Use which to query the absolute path of the command, and then use rpm -qa --queryformat="[%{NAME}: %{INSTFILENAMES}\n]" | grep commondPath to query the corresponding software package.

Three, summary

In all Linux using dpkg and rpm, you can use the above corresponding method to find the software package where the command is located, it's very simple! If you feel helpful, please like and support it! It can be connected three times with one click!

Guess you like

Origin blog.csdn.net/u011074149/article/details/113406093