Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for the source code for common system commands used/available on Linux such as cal, su, sudo, ls, dir, pwd, etc. I want to use the source code to learn more about Linux system administration.

Where is the source code located for system binaries like these—code that is outside the Linux kernel, but distributed with most variants of GNU/Linux?

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

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

share|improve this question

closed as off-topic by RobM, Andrew Schulman, mdpc, Ward, Michael Hampton Oct 24 '14 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.

I noticed on Meta that Jeff said that he'd reopened the question. I feel that it should be reworded a little to "system commands most commonly used/available on Linux" and that would actually make it a little more informative for new administrators. – tudor Feb 18 '15 at 22:11

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
Hence the puritans call it "GNU/Linux". :-) (Meh, it was popular in the 90s/early 00s. Now I'm REALLY showing my age. :-p) – tudor Feb 18 '15 at 22:09
I'd also like to point out that the source code in GNU Coreutils also forms the majority of sourcecode in busybox, which aims to provide a swiss-army-knife approach to system binaries, so that's worth a look also. – tudor Feb 18 '15 at 22:18

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.