Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

Examples of commands I'm referring to are ls, pwd, and cd. Also, how are these built? Do you have an example?

share|improve this question
Is this homework? – Stefan Lasiewski Jul 26 '11 at 17:59
up vote 26 down vote accepted

It's usually plain C. The commands ls and pwd come from the GNU Coreutils package in (most?) Linux distributions (and maybe some other systems). You can find the code on their homepage.

For coreutils specifically, you build them with the usual steps: after unpacking the source, issue:

./configure --prefix=/some/path
                   # type ./configure --help to get the available options
make install       # could require root access depending on the path you used

Be carefull - installing base utilities like those over your distribution's copy of them is a bad idea. Use whatever package manager your system comes with for that. You can install to a different prefix though (installing somewhere into your home directory is a good idea if you want to experiment).

Note that although there is a cd executable, the cd you'll be using in most circumstances isn't a separate executable. It has to be a shell build-in (otherwise it could not change the shell's current directory - this has to be done by the process itself), so it is written in the same language as the shell (which is often C too).

Other examples:

  • OpenSolaris pwd source.
  • FreeBSD ls

You can find many more of these online.

share|improve this answer

Just to add a bit more to Mat's answer, although Unix implements these as standalone programs, many commands are also implemented within bash (to save it having to spawn a new process) see the bash man page for more details, or have a look at the tag.

bash is also written in C

It may be worth noting that these commands do not have to be written in C - indeed, several mini linux distribution use lua implementations of these and others.

share|improve this answer
Well bash, or any other good shell. – rds Aug 16 '11 at 13:19
Note also that some commands such as cd must be a shell builtin to work effectively. – AProgrammer Dec 31 '11 at 15:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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