How to view linux Command source code

Source: Internet
Author: User
For details about how to view the linux Command source code-Linux general technology-Linux technology and application information, see the following. I 've been using linux for a while. Sometimes I want to see the source code of ls, cat, more, and other commands. I haven't found the source code in the downloaded kernel source code. I searched online and summarized the method as follows:

Take the ls command source code as an example. First, search for the package where the command is located. The command is as follows:
Lpj @ lpj-linux :~ $ Which ls
/Bin/ls

Use the command to search for the package of the software. The Code is as follows:
Lpj @ lpj-linux :~ $ Dpkg-S/bin/ls
Coreutils:/bin/ls

From the previous step, we can know the implementation of the ls command in the package coreutils, and install it with apt (indicating that the installation is ambiguous, mainly to distinguish apt-get-d) and decompress the source code of the package, the Code is as follows:
Sudo apt-get source coreutils
#### Cd/usr/src/coreutils-XXX # XXX indicates the version number
Cd.
Sudo tar zxvf coreutils-XXX.tar.gz

Or download the source code, manually patch it, and decompress it. The Code is as follows:
Sudo apt-get-d source coreutils
Cd/usr/src
Tar zxvf coreutils-XXX.tar.gz
Gzip-d coreutils-XXX.diff.gz # This step will generate a coreutils-XXX.diff File
Patch-p0 <coreutils-XXX.diff
Cd coreutils-XXX

OK. After these steps are completed, you can view the source code of each command in/usr/src/coreutils-XXX/src.

Reference: http://zhan.renren.com/ilinux
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.