1. 首页 > Linux教程 > 正文

Linux教程FG108-dnf search/list/info命令(软件包查询)

本文档风哥主要介绍dnf search/list/info命令的使用,包括dnf search/list/info命令的概念、dnf search/list/info命令语法、dnf search/list/info命令常用选项、dnf search/list/info基础操作详解、dnf search/list/info高级使用技巧、DNF软件包查询自动化、软件包安装前查询实战案例、软件包依赖查询实战案例、DNF软件包查询故障排查与解决等内容,参考Red Hat Enterprise Linux 10官方文档,适合Linux运维人员在学习和测试中使用,如果要应用于生产环境则需要自行确认。

Part01-基础概念与理论知识

1.1 dnf search/list/info命令的概念

dnf search/list/info命令是DNF软件包管理器中用于查询软件包的命令。dnf search命令用于搜索软件包,dnf list命令用于列出软件包,dnf info命令用于查看软件包详细信息。这些命令可以帮助用户快速找到需要的软件包,了解软件包的详细信息。更多视频教程www.fgedu.net.cn

dnf search/list/info命令的主要特点:

  • 搜索软件包
  • 列出软件包
  • 查看软件包详细信息
  • 支持多种查询方式
  • 支持正则表达式

1.2 dnf search/list/info命令语法

dnf search/list/info命令语法:

  • 搜索软件包:dnf search [选项] 关键字
  • 列出软件包:dnf list [选项] [软件包]
  • 查看软件包信息:dnf info [选项] 软件包
  • 列出已安装软件包:dnf list installed
  • 列出可更新软件包:dnf list updates

1.3 dnf search/list/info命令常用选项

dnf search/list/info命令常用选项:

  • search:搜索软件包
  • list:列出软件包
  • info:查看软件包信息
  • all:列出所有软件包
  • installed:列出已安装软件包
  • available:列出可用软件包
  • updates:列出可更新软件包
  • obsoletes:列出已废弃软件包
风哥提示:dnf search/list/info命令可以帮助用户快速找到需要的软件包,了解软件包的详细信息。建议熟练掌握这些命令。

Part02-生产环境规划与建议

2.1 DNF软件包查询在生产环境的规划

DNF软件包查询在生产环境的规划要点:

# DNF软件包查询生产环境规划
– 安装软件包前查询
– 了解软件包依赖关系
– 查看软件包详细信息
– 检查软件包版本
– 验证软件包兼容性

# DNF软件包查询注意事项
– 使用精确的关键字
– 检查软件包来源
– 验证软件包完整性
– 了解软件包依赖
– 检查软件包版本

2.2 DNF软件包查询最佳实践

DNF软件包查询最佳实践:

  • 安装前查询:安装软件包前查询
  • 精确搜索:使用精确的关键字
  • 了解依赖:了解软件包依赖关系
  • 查看详情:查看软件包详细信息
  • 验证兼容性:验证软件包兼容性

2.3 DNF软件包查询安全配置建议

DNF软件包查询安全配置建议:

  • 检查来源:检查软件包来源
  • 验证完整性:验证软件包完整性
  • 了解依赖:了解软件包依赖
  • 检查版本:检查软件包版本
  • 验证兼容性:验证软件包兼容性
生产环境建议:安装软件包前查询,使用精确的关键字,了解软件包依赖关系,查看软件包详细信息。学习交流加群风哥微信: itpux-com

Part03-生产环境项目实施方案

3.1 dnf search/list/info基础操作详解

3.1.1 搜索软件包

# 搜索nginx软件包
# dnf search nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
================ Name & Summary Matched: nginx =================
nginx.x86_64 : A high performance web server and reverse proxy server
nginx-filesystem.noarch : The basic directory layout for nginx

# 搜索httpd软件包
# dnf search httpd
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
================ Name & Summary Matched: httpd =================
httpd.x86_64 : Apache HTTP Server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server

3.1.2 列出软件包

# 列出所有软件包
# dnf list all
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Installed Packages
NetworkManager.x86_64 1:1.42.0-5.el9_2 @System
NetworkManager-libnm.x86_64 1:1.42.0-5.el9_2 @System
bash.x86_64 5.1.8-6.el9_2 @System
coreutils.x86_64 8.32-34.el9_2 @System

Available Packages
389-ds-base.x86_64 1.4.3.32-1.el9_2 appstream
389-ds-base-devel.x86_64 1.4.3.32-1.el9_2 appstream
389-ds-base-libs.x86_64 1.4.3.32-1.el9_2 appstream

# 列出已安装软件包
# dnf list installed
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Installed Packages
NetworkManager.x86_64 1:1.42.0-5.el9_2 @System
NetworkManager-libnm.x86_64 1:1.42.0-5.el9_2 @System
bash.x86_64 5.1.8-6.el9_2 @System
coreutils.x86_64 8.32-34.el9_2 @System

# 列出可更新软件包
# dnf list updates
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Available Upgrades
kernel.x86_64 5.14.0-284.11.1.el9_2 baseos
kernel-core.x86_64 5.14.0-284.11.1.el9_2 baseos
kernel-modules.x86_64 5.14.0-284.11.1.el9_2 baseos

3.1.3 查看软件包信息

# 查看nginx软件包信息
# dnf info nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Available Packages
Name : nginx
Version : 1.22.1
Release : 2.el9
Architecture : x86_64
Size : 35 k
Source : nginx-1.22.1-2.el9.src.rpm
Repository : appstream
Summary : A high performance web server and reverse proxy server
URL : http://nginx.org/
License : BSD
Description : Nginx is a web server and a reverse proxy server for HTTP, HTTPS,
: SMTP, POP3 and IMAP protocols, with a strong focus on high concurrency,
: performance and low memory usage.

# 查看httpd软件包信息
# dnf info httpd
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Available Packages
Name : httpd
Version : 2.4.53
Release : 7.el9
Architecture : x86_64
Size : 1.4 M
Source : httpd-2.4.53-7.el9.src.rpm
Repository : appstream
Summary : Apache HTTP Server
URL : https://httpd.apache.org/
License : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
: web server. The Apache HTTP Server is developed and maintained
: by an open community of developers under the auspices of the
: Apache Software Foundation.

3.2 dnf search/list/info高级使用技巧

3.2.1 使用正则表达式搜索

# 使用正则表达式搜索软件包
# dnf search “^http”
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
================ Name & Summary Matched: ^http =================
httpd.x86_64 : Apache HTTP Server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server

# 搜索包含web的软件包
# dnf search web
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
================ Name & Summary Matched: web =================
nginx.x86_64 : A high performance web server and reverse proxy server
httpd.x86_64 : Apache HTTP Server

3.3 DNF软件包查询自动化

3.3.1 自动查询软件包

# 创建软件包查询脚本
# cat > /usr/local/bin/pkg-query.sh << 'EOF' #!/bin/bash # 软件包查询脚本 if [ -z "$1" ]; then echo "Usage: $0
exit 1
fi

echo “=== Searching for package: $1 ===”
dnf search “$1”

echo “”
echo “=== Package information: $1 ===”
dnf info “$1”
EOF

# 设置脚本执行权限
# chmod +x /usr/local/bin/pkg-query.sh

# 使用脚本查询软件包
# /usr/local/bin/pkg-query.sh nginx
=== Searching for package: nginx ===
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
================ Name & Summary Matched: nginx =================
nginx.x86_64 : A high performance web server and reverse proxy server

=== Package information: nginx ===
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Available Packages
Name : nginx
Version : 1.22.1
Release : 2.el9
Architecture : x86_64
Size : 35 k
Source : nginx-1.22.1-2.el9.src.rpm
Repository : appstream
Summary : A high performance web server and reverse proxy server

风哥提示:dnf search/list/info命令支持多种高级选项,如使用正则表达式搜索、自动查询软件包等。学习交流加群风哥QQ113257174

Part04-生产案例与实战讲解

4.1 软件包安装前查询实战案例

4.1.1 安装nginx前查询

# 1. 搜索nginx软件包
# dnf search nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
================ Name & Summary Matched: nginx =================
nginx.x86_64 : A high performance web server and reverse proxy server
nginx-filesystem.noarch : The basic directory layout for nginx

# 2. 查看nginx软件包信息
# dnf info nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Available Packages
Name : nginx
Version : 1.22.1
Release : 2.el9
Architecture : x86_64
Size : 35 k
Source : nginx-1.22.1-2.el9.src.rpm
Repository : appstream
Summary : A high performance web server and reverse proxy server
URL : http://nginx.org/
License : BSD
Description : Nginx is a web server and a reverse proxy server for HTTP, HTTPS,
: SMTP, POP3 and IMAP protocols, with a strong focus on high concurrency,
: performance and low memory usage.

# 3. 查看nginx软件包依赖
# dnf deplist nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
package: nginx.x86_64 1.22.1-2.el9
dependency: /bin/sh
provider: bash.x86_64 5.1.8-6.el9_2
dependency: nginx-core(x86-64) = 1:1.22.1-2.el9
provider: nginx-core.x86_64 1:1.22.1-2.el9
dependency: nginx-filesystem = 1:1.22.1-2.el9
provider: nginx-filesystem.noarch 1:1.22.1-2.el9

# 4. 安装nginx软件包
# dnf install -y nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
nginx x86_64 1:1.22.1-2.el9 appstream 35 k
Installing dependencies:
nginx-core x86_64 1:1.22.1-2.el9 appstream 540 k
nginx-filesystem noarch 1:1.22.1-2.el9 appstream 11 k

Transaction Summary
================================================================================
Install 3 Packages

Total download size: 586 k
Installed size: 1.9 M
Downloading Packages:
(1/3): nginx-filesystem-1.22.1-2.el9.noarch.rpm 11 kB/s | 11 kB 00:00
(2/3): nginx-1.22.1-2.el9.x86_64.rpm 35 kB/s | 35 kB 00:00
(3/3): nginx-core-1.22.1-2.el9.x86_64.rpm 540 kB/s | 540 kB 00:00
——————————————————————————–
Total 586 kB/s | 586 kB 00:00
Running transaction check
Transaction test succeeded
Running transaction
Preparing : 1/1
Installing : nginx-filesystem-1.22.1-2.el9.noarch 1/3
Installing : nginx-core-1.22.1-2.el9.x86_64 2/3
Installing : nginx-1.22.1-2.el9.x86_64 3/3
Running scriptlet: nginx-1.22.1-2.el9.x86_64 3/3
Verifying : nginx-1.22.1-2.el9.x86_64 1/3
Verifying : nginx-core-1.22.1-2.el9.x86_64 2/3
Verifying : nginx-filesystem-1.22.1-2.el9.noarch 3/3

Installed:
nginx-1.22.1-2.el9.x86_64
nginx-core-1.22.1-2.el9.x86_64
nginx-filesystem-1.22.1-2.el9.noarch

Complete!

4.2 软件包依赖查询实战案例

4.2.1 查看软件包依赖关系

# 1. 查看nginx软件包依赖
# dnf deplist nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
package: nginx.x86_64 1.22.1-2.el9
dependency: /bin/sh
provider: bash.x86_64 5.1.8-6.el9_2
dependency: nginx-core(x86-64) = 1:1.22.1-2.el9
provider: nginx-core.x86_64 1:1.22.1-2.el9
dependency: nginx-filesystem = 1:1.22.1-2.el9
provider: nginx-filesystem.noarch 1:1.22.1-2.el9

# 2. 查看nginx-core软件包依赖
# dnf deplist nginx-core
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
package: nginx-core.x86_64 1:1.22.1-2.el9
dependency: /bin/sh
provider: bash.x86_64 5.1.8-6.el9_2
dependency: libc.so.6(GLIBC_2.14)(64bit)
provider: glibc.x86_64 2.34-60.el9_2
dependency: libcrypto.so.1.1(OPENSSL_1_1_1)(64bit)
provider: openssl-libs.x86_64 1:1.1.1k-7.el9_2
dependency: libpcre2-8.so.0()(64bit)
provider: pcre2.x86_64 10.40-2.el9
dependency: libssl.so.1.1(OPENSSL_1_1_1)(64bit)
provider: openssl-libs.x86_64 1:1.1.1k-7.el9_2
dependency: libz.so.1()(64bit)
provider: zlib.x86_64 1.2.11-40.el9
dependency: rtld(GNU_HASH)
provider: glibc.x86_64 2.34-60.el9_2

# 3. 查看nginx-filesystem软件包依赖
# dnf deplist nginx-filesystem
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
package: nginx-filesystem.noarch 1:1.22.1-2.el9
dependency: /bin/sh
provider: bash.x86_64 5.1.8-6.el9_2
dependency: config(nginx-filesystem) = 1:1.22.1-2.el9
provider: nginx-filesystem.noarch 1:1.22.1-2.el9

4.3 DNF软件包查询故障排查与解决

4.3.1 软件包查询失败

# 问题现象:DNF软件包查询失败
# 分析步骤:

# 1. 查看错误信息
# dnf search nginx
Updating Subscription Management repositories.
Error: Failed to download metadata for repo ‘appstream’: Cannot prepare internal mirrorlist: No URLs in mirrorlist

# 2. 清理DNF缓存
# dnf clean all
Updating Subscription Management repositories.
0 files removed

# 3. 重新生成DNF缓存
# dnf makecache
Updating Subscription Management repositories.
Metadata cache created.

# 4. 重新搜索软件包
# dnf search nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
================ Name & Summary Matched: nginx =================
nginx.x86_64 : A high performance web server and reverse proxy server

# 5. 预防措施
# – 定期清理DNF缓存
# – 检查网络连接
# – 验证存储库配置

生产环境建议:DNF软件包查询故障排查需要耐心和细致。软件包查询失败需要检查网络连接和存储库配置。更多学习教程公众号风哥教程itpux_com

Part05-风哥经验总结与分享

5.1 DNF软件包查询经验总结

DNF软件包查询经验总结:

  • 安装前查询:安装软件包前查询
  • 精确搜索:使用精确的关键字
  • 了解依赖:了解软件包依赖关系
  • 查看详情:查看软件包详细信息
  • 验证兼容性:验证软件包兼容性

5.2 DNF软件包查询检查清单

DNF软件包查询检查清单:

  • 查询前:确认软件包名称
  • 查询时:使用精确的关键字
  • 查看详情:查看软件包详细信息
  • 了解依赖:了解软件包依赖关系
  • 验证兼容性:验证软件包兼容性
  • 故障排查:检查网络连接、重新生成缓存

5.3 DNF软件包查询相关工具推荐

DNF软件包查询相关工具推荐:

  • dnf:DNF软件包管理器
  • rpm:RPM包管理器
  • repoquery:软件包查询工具
  • yum-utils:YUM工具集
  • dnf-utils:DNF工具集
风哥提示:dnf search/list/info命令可以帮助用户快速找到需要的软件包,了解软件包的详细信息。建议熟练掌握这些命令。

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息