CentOS下如何获取某个命令的源代码

以ls命令为例,其它命令类似:

1.利用which命令获取命令可执行文件的位置:

[root@228 /]# which ls
alias ls='ls --color=auto'
    /usr/bin/ls

2.利用rpm命令获取命令所在的安装包:

[root@228 /]# rpm -qif /usr/bin/ls
Name        : coreutils
Version     : 8.22
Release     : 15.el7
Architecture: x86_64
Install Date: Mon 23 Apr 2018 10:04:15 PM CST
Group       : System Environment/Base
Size        : 14581114
License     : GPLv3+
Signature   : RSA/SHA256, Wed 25 Nov 2015 10:22:25 PM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : coreutils-8.22-15.el7.src.rpm
Build Date  : Fri 20 Nov 2015 01:36:57 PM CST
Build Host  : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.gnu.org/software/coreutils/
Summary     : A set of basic GNU tools commonly used in shell scripts
Description :
These are the GNU core utilities.  This package is the combination of
the old GNU fileutils, sh-utils, and textutils packages.

3.利用yumdownloader命令下载对应的源安装包:

[root@228 /]# yumdownloader --source coreutils
Loaded plugins: fastestmirror, langpacks
Enabling updates-source repository
Enabling base-source repository
Enabling extras-source repository
base                                                                                                                                                                                       | 3.6 kB  00:00:00     
base-source                                                                                                                                                                                | 2.9 kB  00:00:00     
extras                                                                                                                                                                                     | 3.4 kB  00:00:00     
extras-source                                                                                                                                                                              | 2.9 kB  00:00:00     
updates                                                                                                                                                                                    | 3.4 kB  00:00:00     
updates-source                                                                                                                                                                             | 2.9 kB  00:00:00     
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
coreutils-8.22-21.el7.src.rpm    

4.利用rpm2cpio命令提取源代码,得到源码压缩包(coreutils-8.22.tar.xz):

[root@228 /]# rpm2cpio coreutils-8.22-21.el7.src.rpm | cpio -id
11217 blocks

5.利用xz, tar命令解压即可得命令源代码:

[root@228 /]# xz -d coreutils-8.22.tar.xz 
[root@228 /]# tar xvf coreutils-8.22.tar

coreutils-8.22文件夹下即可找到所需要的源代码。

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值