How to view Linux Command source code and function source code

Source: Internet
Author: User

I 've been using Linux for a while. Sometimes I want to see the source code of the LS, Cat, more, and other commands. I couldn't find the source code in the downloaded kernel source code, but I searched the internet, the methods are summarized as follows:

  1. 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
  2. Use the command to search for the package of the software. The Code is as follows:
    lpj@lpj-linux:~$ dpkg -S /bin/lscoreutils: /bin/ls
  3. 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 coreutilscd/usr/src/coreutils-xxx # XXX indicates the 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 coreutilscd/usr/srctar zxvf coreutils-XXX.tar.gzgzip-D coreutils-XXX.diff.gz # This step will generate the coreutils-XXX.diff file patch-P0 <coreutils-XXX.diffcd coreutils-xxxtar zxvf coreutils-XXX.tar.gz

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

How to view the function source code in the C library?

Google Search: glibc-2.17.tar.bz2, the first link can open, and then click to download glibc library, which has the source code. You can find the corresponding function for the header file.

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.