Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I would like to study the source code of the standard command line functions in Linux such as ls, echo, cat, etc. But I have been unable to find the source code (a Google search was useless).

Does someone know where it's available? I know it's a naive question but I really can't find this source code.

share|improve this question

closed as not constructive by gnat, Bart van Ingen Schenau, thorsten müller, Robert Harvey, MichaelT Apr 8 '13 at 21:33

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

add comment

2 Answers

up vote 5 down vote accepted

Those commands are the GNU core utilities. The latest code can be retrieved from a git repository here:

http://git.savannah.gnu.org/cgit/coreutils.git

To check it out anonymously use git clone like this:

$ git clone git://git.savannah.gnu.org/coreutils.git
share|improve this answer
add comment

There are several implementations of these, the most popular ones being the GNU coreutils (found in most Linux distributions) and the BSD implementation (found in FreeBSD, OS X, and other mostly non-linux Unix-likes).

Unless you are on a distro that installs everything from source (like Gentoo), you will have to ask your package manager to download the sources for you. On Debian-based systems, the appropriate command is apt-get source {package-name}, which downloads the source for the specified package and stores it in the current directory. All that's left is find out which package those commands are in; you can either dig through your package manager's documentation to find out how, or you can search your distro's website - most of them have a package search that allows you to search for individual files within packages.

For Debian-based systems (such as Ubuntu):

$ dpkg -S /bin/rm
coreutils: /bin/rm
$ dpkg -l coreutils
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                         Version                      Description
+++-============================-============================-========================================================================
ii  coreutils                    8.13-3ubuntu3                GNU core utilities

For Red Hat-based systems (such as Fedora and Centos):

$ rpm -qf /bin/rm
coreutils-5.97-34.el5_8.1
share|improve this answer
    
+1 for "ask the package manager". Some Linux distributions make their own changes to package code that isn't reflected in the base sources from GNU. –  Ross Patterson Feb 9 '13 at 22:47
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.