How to obtain the source code of system commands in CentOS
Take the source code of the ls command under the 32-bit CentOS6.6 as an example, you can download the source code using the following method: 1) configure the source code in CentOS, the source configuration file is: /etc/yum. repos. d/CentOS-Base.repo, modifying the file requires root privileges. Open this file and view the content of this file. On my machine, the content of this file is as follows: [plain] view plaincopyprint?
- # CentOS-Base.repo
- #
- # ThemirrorsystemusestheconnectingIPaddressoftheclientandthe
- # Updatestatusofeach?topick=sthatareupdatedtoand
- # Geographicallyclosetotheclient. YoushouldusethisforCentOSupdates
- # Unlessyouaremanuallypickingothermirrors.
- #
- # Ifthemirrorlist = doesnotworkforyou, asafallbackyoucantrythe
- # Remarkedoutbaseurl = lineinstead.
- #
- #
- [Base]
- Name = CentOS-$ releasever-Base
- Using list = http://mirrorlist.centos.org /? Release = $ releasever & arch = $ basearch & repo = OS
- # Baseurl = http://developer.centos.org/centos/?releasever/ OS /?basearch/
- Gpgcheck = 1
- Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
- # Releasedupdates
- [Updates]
- Name = CentOS-$ releasever-Updates
- Using list = http://mirrorlist.centos.org /? Release = $ releasever & arch = $ basearch & repo = updates
- # Baseurl = http://developer.centos.org/centos/?releasever/updates/?basearch/
- Gpgcheck = 1
- Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
- # Additionalpackagesthatmaybeuseful
- [Extras]
- Name = CentOS-$ releasever-Extras
- Using list = http://mirrorlist.centos.org /? Release = $ releasever & arch = $ basearch & repo = extras
- # Baseurl = http://developer.centos.org/centos/?releasever/extras/?basearch/
- Gpgcheck = 1
- Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
- # Additionalpackagesthatextendfunctionalityofexistingpackages
- [Centosplus]
- Name = CentOS-$ releasever-Plus
- Using list = http://mirrorlist.centos.org /? Release = $ releasever & arch = $ basearch & repo = centosplus
- # Baseurl = http://developer.centos.org/centos/?releasever/centosplus/?basearch/
- Gpgcheck = 1
- Enabled = 0
- Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
- # Contrib-packagesbyCentosUsers
- [Contrib]
- Name = CentOS-$ releasever-Contrib
- Using list = http://mirrorlist.centos.org /? Release = $ releasever & arch = $ basearch & repo = contrib
- # Baseurl = http://developer.centos.org/centos/?releasever/contrib/?basearch/
- Gpgcheck = 1
- Enabled = 0
- Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
There are two variables in this file: releasever and basearch, which indicate the release version and branch respectively. For example, on my machine, these two variables are 6 and i386 respectively. Note: releasever will not be subdivided into sub-versions, that is, it will not be 6.6 or the like. We can see from the content of this file that there are five sections in the file, that is, my machine has five software sources: base, updates, extras, centosplus, and contrib. Therefore, you only need to specify the source code for the following five software sources. Add the following content at the end of the file: [plain] view plaincopyprint?
- [Base-src]
- Name = CentOS-$ releasever-Basesrc
- Base url = http://vault.centos.org/6.6/ OS /Source/
- Gpgcheck = 1
- Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
- [Updates-src]
- Name = CentOS-$ releasever-Updatessrc-centos
- Base url = http://vault.centos.org/6.6/updates/Source/
- Gpgcheck = 1
- Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
- [Extras-src]
- Name = CentOS-$ releasever-Extrassrc-centos
- Base url = http://vault.centos.org/6.6/extras/Source/
- Gpgcheck = 1
- Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
- [Centosplus-src]
- Name = CentOS-$ releasever-Plussrc-centos
- Base url = http://vault.centos.org/6.6/centosplus/Source/
- Gpgcheck = 1
- Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
- [Contrib-src]
- Name = CentOS-$ releasever-Contribsrc-centos
- Base url = http://vault.centos.org/6.6/contrib/Soruce/
- Gpgcheck = 1
- Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
The configuration varies depending on different versions. The method can be summarized as follows: (1) the gpgkey is the same as the gpgkey of the existing section in the file (2) to confirm the existence and situation of the file, you can open the website http://vault.centos.org/ (3) set the baseurl according to your system version, such as my host is CentOS-6.6, then at the time of setting, the related parameter is set to 6.6, that is, the submodule connecting http://vault.centos.org/is 6.6. The purpose of this file is to provide a source for the download of yum and its related work. For example, when downloading source code using yumdownloader (as described below), the following action will occur: (1) download $ baseurl/repodata/repomd. xml file, if the repomd. xml files are newer than those in the system, and the corresponding repomd in the system is updated. xml (2) download the source code rpm package in $ baseurl/SPackages. 2) run the which command to view the location of the ls command, as shown below: which ls # output:/bin/ls3) run the rpm command to query the package of the ls command, as shown below: rpm-qf/bin/ls # output: coreutils-8.4-37.el6.i6864) yumdownloader is a program that downloads RPM from the RPM source, you can use the yumdownloader command to install the source code, as follows: yumdownloader -- sourcecoreutils-8.4-37.el6.i686 note :( 1) if the yumdownloader command is not installed, you can use this command to install: yum install yum-utils. (2) The downloaded file is in the current directory. You can use the -- destdir parameter to specify the directory to which the file is downloaded. 5) using yumdownloader to download an installation package file rpm, you can use the following command to query the tar file in rpm: rpm-qpl coreutils-8.4-37.el6.src.rpm | grep tar # output: coreutils-8.4.tar.xz6) use the rpm2cpio command to convert the rpm package file into a cpio archive file, and then use the cpio command to extract an archive file from the cpio archive file copy, as shown below: rpm2cpio coreutils-8.4-37.el6.src.rpm | cpio-idv coreutils-8.4.tar.xz # output: # coreutils-8.4.tar.xz #9561 blockscpio man interpreted as: cpio copies files into an archive-I: equivalent to -- extract, extract meaning-d: it is equivalent to -- make-directories. Create a directory to load-v: The process of listing the file 7)use the tar command to extract coreutils-8.4.tar. xz compressed package, as follows: tar-xvf./coreutils-8.4.tar.xz to this point, the command source code acquisition is complete.