Linux program source code

How can I find the source code for linux commands? [duplicate]

I often come across interesting Linux commands that make me wonder; what are these commands actually doing? Yes, they might be ‘force-removing dependencies’, ‘installing programs’ and doing lots of other stuff, but I’d like to know how they’re doing it. Looking into the source code seems the right thing to do then, but where am I supposed to get it from? I suppose they’ll be written in C? EDIT: I’m not talking about packages installed using apt-get . I’m looking for the source code of linux/unix commands.

The question as is phrased is off-topic and too broad: «Linux commands» doesn’t necessarily pertain to Ubuntu, and the only answer to that would be «visit the command mantainer’s website». And to be honest that wouldn’t be a great question either. If you’re happy with narrowing it down to «Ubuntu’s commands» then the question would be fine, but than it would have been answered already in the duplicate I linked. I don’t see a way out of this honestly.

2 Answers 2

Syntax: apt-get source command-name

Example: apt-get source netstat

Add a Source URI to sources.lst

deb-src http://ftp.de.debian.org/debian lenny main

I think you’re talking about GNU/Debian commands. Linux does not have commands. Most Linux distributions use GNU utilities (that’s why we should call them ‘GNU/Linux’) and their own commands (such as Debian’s APT system). For example, in Ubuntu, commands such as cp , cd , mv are part of the GNU Core Utilities, which are part of the Ubuntu core (base) system. They are represented by the package coreutils . There is an apt-get paramater that you can use to get packages source code: apt-get source . To get coreutils’ source code, use sudo apt-get source coreutils . It’s important to know that commands are nothing more than binaries placed in the paths of the PATH environment variable. These binaries are usually written in C. Also note that commands from some other Unix-like systems, even though they have the same names, are not from the GNU project and sometimes have different syntax. This is the case with the BSD’s (FreeBSD, OpenBSD, NetBSD) and OSX (based in FreeBSD).

Linked

Hot Network Questions

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533

Ubuntu and the circle of friends logo are trade marks of Canonical Limited and are used under licence.

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Read the Source Code of Shell Commands on Linux

To read the source code of shell commands on Linux, you can use the command line utility cat or less to view the file. You can also use a text editor such as vi, nano, or emacs to open and edit the code.

Читайте также:  Eee pc 900 драйвера linux

For example, to view the source code of the ls command, you can use the command −

If you want to view the source code of a command that is installed from a package manager, you can use package manager command to find the location of the source code. For example, on a Debian-based system, you can use the command −

This will list the files included in the package, and you can then navigate to the appropriate file to view the source code.

You can also use the command find to locate the source code of command, for example −

This will search your entire file system for a file named ls, and display its location.

Please note that Some commands may not have a source code, they are built in the shell or are binary files, in those cases you can use the command strings or objdump to see some of the code that the command is using.

Find the Source Code

To find the source code of a particular program, there are several methods you can try −

Check the official website of the program or project. Many open-source programs have their source code available for download on their official website.

Search for the program on GitHub, GitLab, or other code hosting platforms. Many open-source programs are hosted on these platforms, and you can easily find and download the source code.

Use package manager command, like apt-get source, yumdownloader, dnf download etc depends on the Linux distribution. These commands will download the source code of the package for you.

Check for the source code in the program’s documentation. Some programs include links to their source code in their documentation.

Use a search engine to find the source code. You can search for the program’s name followed by the keywords «source code» or «github» to find the source code.

It’s worth noting that some software is closed-source, and the source code is not publicly available. In this case, you will not be able to find the source code.

Use the Package Manager

To use a package manager to find and download the source code of a program, you will first need to know the name of the package that the program is contained in. Once you know the package name, you can use the package manager command to download the source code.

Here are some examples of how to use a package manager to download the source code of a program on different Linux distributions −

On Debian-based systems (such as Ubuntu), you can use the command apt-get source to download the source code of a package. For example, to download the source code of the ls command, you would use the command −

On Fedora, Red Hat and CentOS systems, you can use the command yumdownloader —source to download the source code of a package. For example, to download the source code of the ls command, you would use the command −

yumdownloader --source coreutils

On Arch Linux-based systems, you can use the command pacman -S —needed base-devel to install the base development package, and then yaourt -S —aur to download the source code of a package.

Читайте также:  Linux нет нижней панели

On OpenSuse systems, you can use the command zypper source-install to download the source code of a package.

It’s worth noting that some packages may not have the source code available, in that case you will get an error message.

Also it’s good to note that before installing or building the source code, make sure you have the necessary dependencies and development tools installed on your system.

Debian-Based Systems

On Debian-based systems (such as Ubuntu, Mint, Debian, etc), you can use the apt-get command to download the source code of a package. The apt-get source command will download the source code of a package and all of its dependencies.

Here’s an example of how to use the apt-get command to download the source code of the ls command on a Debian-based system −

This command will download the source code of the package coreutils which includes ls command, and all of its dependencies. The source code will be downloaded to the current working directory, and will be in the form of a .tar.gz file.

You can also use apt-get build-dep to install the dependencies required to build the package.

You can then extract the source code using the command tar -xzvf .tar.gz, and then navigate to the extracted directory to build and install the package using the command dpkg-buildpackage -us -uc

It’s worth noting that apt-get source command will download the source code of the package in the version that is currently installed on your system. If you want to download a specific version of the package source code, you can use the -t option followed by the version number you want to download.

For example, to download version 8.31 of the coreutils package, you can use the command −

apt-get source -t 8.31-1 coreutils

Also, it’s good to note that you need to have the apt-src package installed on your system to use the apt-get source command.

Red Hat-Based Systems

On Red Hat-based systems (such as Fedora, Red Hat Enterprise Linux, CentOS, etc), you can use the yumdownloader command to download the source code of a package.

Here’s an example of how to use the yumdownloader command to download the source code of the ls command on a Red Hat-based system −

yumdownloader --source coreutils

This command will download the source code of the package coreutils, which includes the ls command, in the form of a .src.rpm file. The downloaded file will be located in the current working directory.

You can also use the yum-builddep command to install the dependencies required to build the package.

You can then use the rpmbuild command to extract the source code, and build the package.

It’s worth noting that yumdownloader command will download the source code of the package in the version that is currently installed on your system. If you want to download a specific version of the package source code, you can use the —releasever option followed by the version number you want to download.

For example, to download version 8.31 of the coreutils package, you can use the command −

yumdownloader --releasever=8.31 --source coreutils

Also, it’s good to note that you need to have the yum-utils package installed on your system to use the yumdownloader command.

Читайте также:  Linux bridge not forward

Conclusion

To find and download the source code of a program on Linux, you can use the package manager command that corresponds to your Linux distribution. On Debian-based systems, you can use the apt-get source command, and on Red Hat-based systems, you can use the yumdownloader —source command.

Источник

Where do you download Linux source code? [closed]

Say I’m interested in the source for one particular Linux utility, like factor . Where can I find the source code for that utility?

8 Answers 8

You can also find out which package the binary comes from an download that packages source code.

On Debian (and Ubuntu and anything else that’s based on Debian) you do that like this:

$ dpkg -S /usr/bin/factor coreutils: /usr/bin/factor $ apt-get source coreutils

The first command will check which package contains the file you are searching for (use » which factor » to find out which binary is executed when you just type » factor «).

The second command will download and unpack the sources (including the patches applied to build the package) to the current directory, so it should be executed in a dedicated or temporary directory.

I’m pretty sure rpm -based distributions have a similar mechanism, but I don’t know their commands.

Thanks, that’s a good, non-Google option. I know Google will always be there, but for some reason I still like knowing how to live without it.

and went to the bottom and found ‘GNU coreutils 6.10’. So I googled ‘coreutils’ and. found the site joschi just linked to.

Thanks, this (a general explanation of how to find the source for a given program) is what I was after.

That may not be a good idea for all things. Some distributions may have modified the original for their distribution. It may be a better idea to use the package management software that comes with you system (Package management can get source as well as binaries) See ‘Saua’ below.

To find the package a binary comes from, in rpm based system, you might type:

which will print the package name. Instead, with:

you will get also information on a package, including it’s home page in many cases.

Source rpms also exist, but how to get them depends on the high-level package manager used on top of RPM (yum, urpmi, apt-get4 for rpm, . ).

On most systems, also, /usr/share/doc/ contains some documentation on the program, and the website link is pretty often found somewhere there, maybe in the README.

Usually you’ll find the source code on the website of the program if it is open source. In this case here since factor is part of coreutils.

On Gentoo, simply look in the ebuild you compiled the package with :D.

# which factor /usr/bin/factor # grep '/usr/bin/factor' /var/db/pkg/*/*/CONTENTS /var/db/pkg/sys-apps/coreutils-6.12-r2/CONTENTS:obj /usr/bin/factor 5aaf903daa4345efb11618b3cb47e9a5 1224224574 /var/db/pkg/sys-apps/coreutils-6.12-r2/CONTENTS:obj /usr/lib64/debug/usr/bin/factor.debug 517d965636850633e9b15926dde8c222 1224224575 # cat /var/db/pkg/sys-apps/coreutils-6.12-r2/SRC_URI ftp://alpha.gnu.org/gnu/coreutils/coreutils-6.12.tar.lzma mirror://gnu/coreutils/coreutils-6.12.tar.lzma mirror://gentoo/coreutils-6.12.tar.lzma mirror://gentoo/coreutils-6.12-patches-1.0.tar.lzma http://dev.gentoo.org/~vapier/dist/coreutils-6.12-patches-1.0.tar.lzma # cat /var/db/pkg/sys-apps/coreutils-6.12-r2/HOMEPAGE http://www.gnu.org/software/coreutils/

But of course, the source code is probably still available in /usr/portage/distfiles .

Источник

Оцените статью
Adblock
detector