View and download the command source package under Linux (reverse the command/application to get and install the source bundle)

Source: Internet
Author: User
Tags rpmbuild

In the process of using Linux, we will be familiar with various commands, occasionally we can not help but ask how these commands are implemented, learning they are actually learning Linux advanced system programming very fast method.

The source of these commands must be stored in the corresponding package, but which packages?

The release Package Manager provides a convenient command interface for us to find the package we specify in the command

For example, we use the most common uname command to illustrate,

    • Use the Whereis or which command to find the absolute position of the command

    • Search the package information that the command belongs to by using the RPM or DPKG command

    • Download and install the corresponding source code source package, you can get the source code

CentOS and other RPM Package Manager search Sobin download command belongs to the package

How to view the source code of a command
For example, to see the source code for this command uname

## 查看命令which uname   ## /bin/uname##查看命令所属的包   rpm -qf /bin/uname##下载对应的xxx.src.rpm源码包yumdownloader --source coreutils-版本号

[Question 1]

Without Yumdownloader, you can install it like this.

install yum-utils

[Question 2]

If you are prompted no Match for argument coreutil-5.97-23.el5_4.2

The description source may not have this package, then we can only manually download

To the package site http://vault.centos.org download the corresponding version of the package can be

Attention

What we need is the source package, so the download should be XXX.SRC.RPM's package.

Installation or decompression source package to get the source code

After downloading the source package there are two ways to view the source package,

The first of these methods

rpm -qpl coreutils-8.5-7.fc14.src.rpm##查询rpm中的tar文件,源码一般放在这里##从rpm包中提取指定的文件rpm2cpio coreutils-8.5-7.fc14.src.rpm | cpio -idv coreutils-8.5.tar.xztar xjvf coreutils-8.5.tar.xz##到解压出来的coreutils-8.5/src/中就能找到相关的源码了

The second method: Install the source package

rpm -i coreutils-8.5-7.fc14.src.rpm##安装源码包

CentOS and Rhel are generally installed after the source code under/usr/src/redhat under the various directories, but Fedora is in ~/rpmbuild/sources/

You can query where the code package is installed through the Locate command

Locate Coreutils*tar
/home/workhard/tmp/coreutils-8.5.tar.xz
/home/workhard/rpmbuild/sources/coreutils-8.5.tar.xz
Cd/home/workhard/rpmbuild/sources/c

tar Jxvf coreutils-8.5.tar.xzcd coreutils-8.5/src/ll uname*

How to uninstall after installing *.src.rpm

cd/home/gatieme/rpmbuild/SOURCESrpmbuild--rmsource--rmspeccoreutils.spec

Related Instructions Yumdownloader

Yumdownloader comes from the Yum-utils package, if you don't have that installed already.

Yum Install Yum-utils

RPM usage
...in package.-qf:查找指定文件属于哪个RPM软件包-qpl:列出RPM软件包内的文件信息;
Rpm2cpio
Packagepackage.

As the name implies, Rpm2cpio is converting RPM package files into Cpio archive files

Cpio usage

Cpio-copy files to and from archives

-i 抽取的意思,和"--extract"等同-d 建立目录,和"--make-directories"等同-v 冗余信息输出,和"--verbose"等同
Rpmbuild usage
--rmsourcetheafterthe build--rmspecthefileafterthe build
Ubuntu and other Deb packages

Unlike the RPM packages of the Redhat series, Ubuntu uses the Debian Deb package, so the search and installation methods are slightly different, but the idea is the same

Find out which package the command you want to see source belongs to:

-S`which cp`

Coreutils:/BIN/CP

Download Source:

-dsource"coreutils"
Other distributions

In fact, we can see from the above process, most of the command source code is in the package coreutils, other distributions directly download can

http://ftp.gnu.org/gnu/coreutils/

Coreutils is a software package under GNU that contains common commands such as LS under Linux. The implementation of these commands depends on the shell program.

Gnu/coreutils is a set of basic software packages that are required for Unix-like operating systems. It contains three sets of commands, common commands such as cat, LS, RM.

For some other non-standard packages, we can use the same approach, because these commands are necessary to install the package or application that comes with it, such as Git

such as the top command, etc., is located in the Procps package

View and download the command source package under Linux (reverse the command/application to get and install the source bundle)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.