View Linux Command source code

Source: Internet
Author: User

In normal homework, sometimes the teacher asks himself to implement programs such as CAT, sometimes using shell, and sometimes using C, but I often have no clue at all, however, I think of Linux open-source, and the command code can be used for reference. So I want to see the source code of the Linux Command, so I started the search process of the dog. From the results, there are two situations: one is the form of giving RPM package; the other is based on the form of Deb package. I don't know how to describe it. In short, it is a RedHat source code view, and a Debian source code view. I use Ubuntu, which is based on Debian, so the previous RPM method did not work.
Below I will summarize: the source code is stored in the corresponding package.
I searched coreutils in the new profit and found that it has been installed. However, the software should be installed here, that is, the command execution file. However, I have not found whether SRC is installed, that is, the source code.
PS:
The coreutils package contains tools for displaying and setting basic system features.
Procedure 1 (Linux rwind-Ubuntu 2.6.22-14-generic ):
1. First find the package of the command you want to view


Rwind @ rwind-Ubuntu :~ $ Dpkg-s 'which ls'
Coreutils:/bin/ls
Coreutils is the package where the source code is located. Download the package below.
Similarly:
Rwind @ rwind-Ubuntu :~ /Source $ dpkg-s 'which which'
Debianutils:/usr/bin/which
Debianutils is the package where which is located.
The first mistake I made: Use ''as''. The two are different. The first one is the quotation mark on the left of the number key 1, the function is to execute and replace the content in ''as a command in shell command line reorganization with the result.
2. Download the corresponding source code package
Rwind @ rwind-Ubuntu :~ /Source $ apt-get-D source "debianutils" is reading the package list... complete the dependency tree reading status information of the software package being analyzed... complete the download of the 134kb source code package. Get: 1 http://ubuntu.cn99.com feisty/main debianutils 2.17.4build1 (DSC) [479b] Get: 2 http://ubuntu.cn99.com feisty/main debianutils 2.17.4build1 (TAR) [133kb] Download 134kb, it takes 1 S (90.7kb/s) to download. Currently, the download only mode is used.
The D option is only the download option. Download to your current working directory.
3. decompress the downloaded package and find the package on your own. There are a lot of files. I don't know what the functions are. I will study it later and find out it slowly.
In addition, I found some information on the Internet, but I did not verify it,
The original article is as follows:
Apt-Get install apt-File
Apt-file update
Apt-file search/bin/ls
In this way, we can know that ls is provided by coreutils.
Then apt-Get source coreutils will get the source code.
Of course, for LS, you can also use dpkg-S/usr/ls to query which package it belongs to, But dpkg-S is only valid for installed packages
II. This is the RPM package format I searched online.
Take the find command as an example:

Step 1: Determine which RPM package the command belongs:
# Rpm-qf/usr/bin/find
Findutils-4.1-34

The second step, find findutils source code package findutils-4.1-34.src.rpm, which can be found in the release of the website

Step 3: Install the source package:
Rpm-IVH findutils-4.1-34.src.rpm
After installation, you can find the relevant source code package under/usr/src/RedHat/source.
This is probably the case. In the future, we will add some deficiencies. If you have any suggestions or errors, I hope you can give some advice. Thank you.

This article is from the chinaunix blog. If you want to view the original text, click:Http://blog.chinaunix.net/u1/54537/showart_431031.html

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.