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?

  • 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. – tu-Reinstate Monica-dor duh 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:

  • Hence the puritans call it "GNU/Linux". :-) (Meh, it was popular in the 90s/early 00s. Now I'm REALLY showing my age. :-p) – tu-Reinstate Monica-dor duh 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. – tu-Reinstate Monica-dor duh 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.


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.


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.

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