How to obtain the source code of system commands in CentOS

Source: Internet
Author: User

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?

  1. # CentOS-Base.repo
  2. #
  3. # ThemirrorsystemusestheconnectingIPaddressoftheclientandthe
  4. # Updatestatusofeach?topick=sthatareupdatedtoand
  5. # Geographicallyclosetotheclient. YoushouldusethisforCentOSupdates
  6. # Unlessyouaremanuallypickingothermirrors.
  7. #
  8. # Ifthemirrorlist = doesnotworkforyou, asafallbackyoucantrythe
  9. # Remarkedoutbaseurl = lineinstead.
  10. #
  11. #
  12. [Base]
  13. Name = CentOS-$ releasever-Base
  14. Using list = http://mirrorlist.centos.org /? Release = $ releasever & arch = $ basearch & repo = OS
  15. # Baseurl = http://developer.centos.org/centos/?releasever/ OS /?basearch/
  16. Gpgcheck = 1
  17. Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
  18. # Releasedupdates
  19. [Updates]
  20. Name = CentOS-$ releasever-Updates
  21. Using list = http://mirrorlist.centos.org /? Release = $ releasever & arch = $ basearch & repo = updates
  22. # Baseurl = http://developer.centos.org/centos/?releasever/updates/?basearch/
  23. Gpgcheck = 1
  24. Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
  25. # Additionalpackagesthatmaybeuseful
  26. [Extras]
  27. Name = CentOS-$ releasever-Extras
  28. Using list = http://mirrorlist.centos.org /? Release = $ releasever & arch = $ basearch & repo = extras
  29. # Baseurl = http://developer.centos.org/centos/?releasever/extras/?basearch/
  30. Gpgcheck = 1
  31. Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
  32. # Additionalpackagesthatextendfunctionalityofexistingpackages
  33. [Centosplus]
  34. Name = CentOS-$ releasever-Plus
  35. Using list = http://mirrorlist.centos.org /? Release = $ releasever & arch = $ basearch & repo = centosplus
  36. # Baseurl = http://developer.centos.org/centos/?releasever/centosplus/?basearch/
  37. Gpgcheck = 1
  38. Enabled = 0
  39. Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
  40. # Contrib-packagesbyCentosUsers
  41. [Contrib]
  42. Name = CentOS-$ releasever-Contrib
  43. Using list = http://mirrorlist.centos.org /? Release = $ releasever & arch = $ basearch & repo = contrib
  44. # Baseurl = http://developer.centos.org/centos/?releasever/contrib/?basearch/
  45. Gpgcheck = 1
  46. Enabled = 0
  47. 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?
  1. [Base-src]
  2. Name = CentOS-$ releasever-Basesrc
  3. Base url = http://vault.centos.org/6.6/ OS /Source/
  4. Gpgcheck = 1
  5. Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
  6. [Updates-src]
  7. Name = CentOS-$ releasever-Updatessrc-centos
  8. Base url = http://vault.centos.org/6.6/updates/Source/
  9. Gpgcheck = 1
  10. Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
  11. [Extras-src]
  12. Name = CentOS-$ releasever-Extrassrc-centos
  13. Base url = http://vault.centos.org/6.6/extras/Source/
  14. Gpgcheck = 1
  15. Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
  16. [Centosplus-src]
  17. Name = CentOS-$ releasever-Plussrc-centos
  18. Base url = http://vault.centos.org/6.6/centosplus/Source/
  19. Gpgcheck = 1
  20. Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
  21. [Contrib-src]
  22. Name = CentOS-$ releasever-Contribsrc-centos
  23. Base url = http://vault.centos.org/6.6/contrib/Soruce/
  24. Gpgcheck = 1
  25. 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.

Related Article

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.