The linuxfromscratch link provided by EricTRA was indeed a good starting point. I suggest an alternative and a method you can follow for other similar searches in the future. First use the type
command to see which is the actual command executed (take in mind that some commands like echo
, can be either a shell built-in or a standalone program. The type command will tell you which of them is currently used by your system).
$ type fg
fg is a shell builtin
as you can see the fg command is a shell built-in. And it is only and uniquely a shell built-in. This means the source code of fg
is built into the code of the shell itself. If using BASH, your best bet to find the code you're looking for is to download the source code for bash (eventually verify which version of bash you've installed and download that exact version).
Take in mind that bash - as any other GNU software - is available for download at the GNU website, www.gnu.org
If your intent is to apply a patch, first it is strongly advised that you apply only the official ones. And it is even more strongly suggested that you wait for the updated package released by your linux distribution. Said that, since you're running on a RPM based system, if you really want to apply a patch you can download the source RPM and rebuild it.
Back to the search of source code in general, suppose the type
command returns the path to an executable (here we are talking about an external program - external as opposite of shell built-in). In this case you can try the rpm
command to find out which package provided the executable, then you can look for and download the source code on the official (developer or project) site. Here is an example, taken from my CentOS box:
$ type thunderbird
thunderbird is /usr/bin/thunderbird
$ rpm -qf /usr/bin/thunderbird
$ rpm -qi thunderbird
Name : thunderbird Relocations: (not relocatable)
Version : 188.8.131.52 Vendor: CentOS
Release : 2.el5.centos Build Date: Fri 26 Jun 2009 12:08:45 AM CEST
Install Date: Thu 16 Jul 2009 12:52:15 PM CEST Build Host: builder16.centos.org
Group : Applications/Internet Source RPM: thunderbird-184.108.40.206-2.el5.centos.src.rpm
Size : 47338016 License: MPL
Signature : DSA/SHA1, Fri 26 Jun 2009 04:07:53 PM CEST, Key ID a8a447dce8562897
URL : http://www.mozilla.org/projects/thunderbird/
Summary : Mozilla Thunderbird mail/newsgroup client
Mozilla Thunderbird is a standalone mail and newsgroup client.
Next step is to browse the official site and look for the source code.
Take in mind that in many cases you will be able to find the source code as source RPMs. This is especially true for software/packages built and provided by the official linux distribution you're running on. Just adding the Source RPM repository to the list of available software sources, should let you have easy and quick access to the code.
Hope this helps!