centos 查看命令源码

centos 查看命令源码

# yum install yum-utils


设置源:
[base-src]
name=CentOS-5.4 - Base src -
baseurl=http://vault.centos.org/5.4/os/SRPMS/
#mirrorlist=http://mirrorlist.centos.org/?release=5.4&arch=SRPMS&repo=os
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5


[updates-src]
name=CentOS-5.4 - Updates src-centos
baseurl=http://vault.centos.org/5.4/updates/SRPMS/
#mirrorlist=http://mirrorlist.centos.org/?release=5.4&arch=SRPMS&repo=updates
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5


#packages used/produced in the build but not released
[addons-src]
name=CentOS-5.4 - Addons src -
baseurl=http://vault.centos.org/5.4/addons/SRPMS/
#mirrorlist=http://mirrorlist.centos.org/?release=5.4&arch=SRPMS&repo=addons
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5


#additional packages that may be useful
[extras-src]
name=CentOS-5.4 - Extras src-centos
baseurl=http://vault.centos.org/5.4/extras/SRPMS/
#mirrorlist=http://mirrorlist.centos.org/?release=5.4&arch=SRPMS&repo=extras
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5


#additional packages that extend functionality of existing packages
[centosplus-src]
name=CentOS-5.4 - Plus src-centos
baseurl=http://vault.centos.org/5.4/centosplus/SRPMS/
#mirrorlist=http://mirrorlist.centos.org/?release=5.4&arch=SRPMS&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5


#contrib - packages by Centos Users
[contrib-src]
name=CentOS-5.4 - Contrib src-centos
baseurl=http://vault.centos.org/5.4/contrib/SRPMS/
#mirrorlist=http://mirrorlist.centos.org/?release=5.4&arch=SRPMS&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5

 

怎么查看某个命令的源代码

比如想查看uname这个命令的源代码

[root@localhost usr]# whereis uname

uname: /bin/uname /usr/share/man/man1/uname.1.gz /usr/share/man/man2/uname.2.gz /usr/share/man/man1p/uname.1p.gz /usr/share/man/man3p/uname.3p.gz

[root@localhost usr]# rpm -qf /bin/uname

coreutils-8.5-7.fc14.i686

##没有yumdownloader 的话可以这样子安装#yum install yum-utils

[workhard@localhost tmp]$ yumdownloader --source coreutils-8.5-7.fc14.i686 ##source下载源码包

到这一步后有两种方法可以查看到源码包,第一种方法

[workhard@localhost tmp]$ rpm -qpl coreutils-8.5-7.fc14.src.rpm | grep tar ##查询rpm中的tar文件,源码一般放在这里

coreutils-8.5.tar.xz

##rpm包中提取指定的文件

[workhard@localhost tmp]$ rpm2cpio coreutils-8.5-7.fc14.src.rpm | cpio -idv coreutils-8.5.tar.xz

coreutils-8.5.tar.xz

9446 blocks

[workhard@localhost coreutils-8.5]$ tar xjvf coreutils-8.5.tar.xz

##到解压出来的coreutils-8.5/src/中就能找到相关的源码了

第二种方法:安装源码包

[workhard@localhost tmp]$ rpm -i coreutils-8.5-7.fc14.src.rpm ##安装源码包

warning: user mockbuild does not exist - using root

warning: group mockbuild does not exist - using root

##centosrhel一般安装后的源码在/usr/src/redhat下的各个目录下,fedora是在~/rpmbuild/SOURCES/

##可以通过locate命令查询代码包被安装到哪里了

[workhard@localhost tmp]$ locate *coreutils*tar*

/home/workhard/tmp/coreutils-8.5.tar.xz

/home/workhard/rpmbuild/SOURCES/coreutils-8.5.tar.xz

[workhard@localhost tmp]$ cd /home/workhard/rpmbuild/SOURCES/c

[workhard@localhost SOURCES]$ tar Jxvf coreutils-8.5.tar.xz

[workhard@localhost src]$ cd coreutils-8.5/src/

[workhard@localhost src]$ ll uname*

-rw-r--r--. 1 workhard workhard 48 Jan 1 2010 uname-arch.c

-rw-r--r--. 1 workhard workhard 10024 Jan 1 2010 uname.c

-rw-r--r--. 1 workhard workhard 146 Jan 1 2010 uname.h

-rw-r--r--. 1 workhard workhard 49 Jan 1 2010 uname-uname.c

安装*.src.rpm后怎么卸载

[workhard@localhost SOURCES]$ cd /home/workhard/rpmbuild/SOURCES

[workhard@localhost SPECS]$ rpmbuild --rmsource --rmspec coreutils.spec

**相关说明

一、yumdownloader comes from the yum-utils package, if you don't have that installed already.

#yum install yum-utils

二、RPM用法

rpm {-i|--install} [install-options] PACKAGE_FILE ...

-f, --file FILE

Query package owning FILE.

-p, --package PACKAGE_FILE

Query an (uninstalled) package PACKAGE_FILE.

-l, --list

List files in package.

qf:查找指定文件属于哪个RPM软件包

qpl:列出RPM软件包内的文件信息;

三、rpm2cpio - Extract cpio archive from RPM Package Manager (RPM) package.

顾名思义,rpm2cpio是将rpm包文件转换成cpio归档文件

四、CPIO用法

cpio - copy files to and from archives

-i 抽取的意思,和"--extract"等同

-d 建立目录,和"--make-directories"等同

-v 冗余信息输出,和"--verbose"等同

五、rpmbuild用法

--rmsource

Remove the sources after the build

--rmspec

Remove the spec file after the build