Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am looking for the source code for common commands ( such as cal, su, sudo, ls -l, dir, pwd etc. ). I want to use the source code to learn more about Linux for all the common commands.

Where is the source code for these commands that are present in Linux distributions?

Which Linux distribution is best for learning and viewing the source code for these commands present in Linux?

Is it possible to alter the code to learn how they really works?

share|improve this question

closed as off-topic by RobM, Andrew Schulman, mdpc, Ward, Michael Hampton Oct 24 at 12:49

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions must be relevant to professional system administration. Server Fault is dedicated to professional system and network administrators. End user and enthusiast questions are off-topic (contact your system administrator or hire a professional to help you out). Please see the Help Center for more information." – Andrew Schulman, mdpc, Ward, Michael Hampton
If this question can be reworded to fit the rules in the help center, please edit the question.

4 Answers 4

It is worthwhile to keep in mind that "Linux" refers to just the kernel. The basic commands come from the GNU Coreutils package, as well as from many other similar packages.

When looking for things like this though, I usually go to the FreeBSD SVN Repository, which I find easier to navigate than multiple GNU packages. For example, the source for ls can be found here:

share|improve this answer

If you are looking for an all source Linux distro, you should look into installing Gentoo.

Otherwise you can go a more "manual" route and try sharpening your teeth with Linux From Scratch, which seems to be what you are looking for. It's a step by step guide to build an usable Linux system from the ground up. It has a detailed explanation of what every package is, and how to build them. It's a bit daunting, and you most definitely should follow it with Beyond Linux From Scratch, which is aimed at having a functional Linux system.

If all you want is to look at those common applications, you could just download the Coreutils package.

share|improve this answer

Generally, you can just google for sources of respective utilites. In debian-based distros you can use apt-get to download (debianized) sources: e.g. apt-get source sudo will download and unpack sources for sudo. To find out what package utility belongs to, you can use dpkg -S /usr/bin/sudo or, if you can use apt-file to search for files in non-installed packages.

share|improve this answer

You can obtain source code of packages by installing source package or by downloading source from the package website. The package you are interested in is called coreutils. How to install source package will depend on distribution of Linux you are using. But if you want to download source from package website you can visit coreutils download ftp site.

Each distribution might have changed basic package to improve options or change defaults. But more or less the base code is same as you will find on the GNU website.

share|improve this answer

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