最近工作上遇到了将rpm
包解压得到子包的场景。以前一直以为rpm
包就是一种Linux
上的安装包,直接执行安装命令进行安装即可,今天查了下,其应用还不止于此
RPM的全称是RPM Package Manager,原本叫Red Hat Package Manager,用于在Linux上安装、卸载、管理软件包的。这乍一听怎么和yum有点像?
首先,yum是什么呢?官方的介绍如下:
What is yum?
yum is the primary tool for getting, installing, deleting, querying, and managing Red Hat Enterprise Linux RPM software packages from official Red Hat software repositories, as well as other third-party repositories. yum is used in Red Hat Enterprise Linux versions 5 and later. Versions of Red Hat Enterprise Linux 4 and earlier used up2date.
这货就是专门用来安装rpm包的
而且,yum
官方介绍提到了 installing
, deleting
, managing
那么来看下RPM的官方描述
The RPM Package Manager (RPM) is an open packaging system, which runs on Red Hat Enterprise Linux as well as other Linux and UNIX systems. Red Hat, Inc. encourages other vendors to use RPM for their own products. RPM is distributed under the terms of the GPL
The utility works only with packages built for processing by the rpm package. For the end user, RPM makes system updates easy. Installing, uninstalling, and upgrading RPM packages can be accomplished with short commands
首先,RPM是一个打包系统,而rpm是该打包系统的一个包格式。而它的管理则是可以安装、卸载、升级rpm,总结下就是:
RPM(Red Hat Package Manager)是一个 打包格式,也是一个工具,用于管理和处理这种格式的包。在基于 RPM 的系统(如 Red Hat、CentOS、Fedora 等)中,rpm 包是用来分发和安装软件的标准格式
更多关于RPM介绍可以直接参考Package Management with RPM
回到解压rpm,当时工作群里给出了这样一条命令
rpm2cpio xxxx.noarch.rpm | cpio -idvm
首先,rpm2cpio 的作用是:
rpm2cpio - Extract cpio archive from RPM Package Manager (RPM) package.
As the name implies, rpm2cpio takes an RPM package file and converts it to a cpio archive. Because it’s written to be used primarily as a filter, there’s not much to be specified. rpm2cpio takes only only one argument, and even that’s optional!
它的参数仅有xxxx.noarch.rpm,也就是待处理的文件。其次,rpm2cpio主要是作为过滤器,也就是读取输入,然后rpm2cpio is written as a filter. It writes the cpio archive contained in the package file to standard output
,那么此时|就发挥作用了,| cpio -idvm
-i:表示“input”(输入),指示 cpio 从归档文件中提取文件。
-d:表示“create directories”(创建目录),如果归档中包含了目录结构,cpio 会自动创建相应的目录。
-v:表示“verbose”(详细模式),会显示正在提取的文件名,便于跟踪提取过程。
-m:表示“preserve modification time”(保留修改时间),在提取文件时会保留原始文件的时间戳(修改时间)
所以简单概括下就是:
rpm2cpio 是一个用于将 RPM 包文件转换为 CPIO 格式的工具,主要用于提取 RPM 包中的单个或多个文件。它通常作为一个过滤器使用,将 RPM 包转换为 CPIO 格式流,并通过管道传递给 cpio 命令,后者负责提取文件或列出文件内容
参考:
- https://access.redhat.com/solutions/9934
- https://www.techtarget.com/searchdatacenter/definition/RPM-Package-Manager-Red-hat-Package-Manager
- https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/5/html/deployment_guide/ch-rpm#ch-rpm
- https://man7.org/linux/man-pages/man8/rpm2cpio.8.html
- http://ftp.rpm.org/max-rpm/s1-rpm-miscellania-rpm2cpio.html