以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文件夾下即可找到所需要的源代碼。