Thursday, March 7, 2013

Where do I find source code of linux commands?

Q. Linux commands like cp, dir, ls, shred, man (etc...) are nothing but programs (hopefully all written in C). I would really like to know exactly how they work (and make a few modifications to some) so I need their source code...
Can you tell me where to find source code of linux commands?
Thank you in advance!

A. In general there are several places you can go to get the source for these commands. This is mostly because there can be several different implementations of the commands.

1) The company who distributed your version of Linux. Most versions of these types of commands are under the GPL and as such the person or company who gave you the executable has to make a copy of the source code available to you. Usually these are released as source rpms, and some times come on one of the CDs or DVDs that you used to install Linux with. You can often find them on the web too.

For example the RHEL5 Server source rpm (SRPM) is
ftp://ftp.redhat.com/pub/redhat/linux/enterprise/5Server/en/os/SRPMS/coreutils-5.97-12.1.el5.src.rpm

Most of the time your distribution will have a tool like yum to install these and other rpms for you.

2) www.gnu.org
GNU probably wrote the commands that are on your distribution of Linux, although a few very specialized distros use different implementations of the commands (Usually busybox http://www.busybox.net/ but this is really rare).

http://www.gnu.org/software/coreutils/
has instructions on how to download a very recent copy of the code, which may be much much newer then the version currently installed on your computer.

NOTE:

Some shells, like tcsh and csh have their own implementations of these commands built into them. This is because it is faster to run the command as part of your shell then to fork and exec a new command. So if you do change them be sure to check that you are actually running your updated version. BASH usually does not play these games but you can always check by running which followed by the name of your command.

How to capture C and CPP files in the linux operating system?
Q. I am new to linux and have been trying to figure this out forever for a homework assignment! I am supposed to use appropriate linux commands to capture all "C or CPP" files in the linux operating system and make a list of the files. I am using Xubuntu. I am a beginner and could use any advice! Thanks!

A. What does it mean to capture a file??

If you mean to find the files and list the results, use the 'find' command to search for *.c and *.cpp files in the whole system. You will get the result on the screen, and you can redirect the output to a file.

To find *.c files:
find / -name *.c

To find *.cpp files:
find / -name *.cpp

Explanation: the "/" means to start the search at the top of the file system, meaning that the search will include all the system. The "-name" means to search by name, and "*.c" is the file pattern you want to find.

To redirect the output, use "> output_file" for example:
find / -name *.cpp > output_file

Hope it helps. See the manual page 'man find' to learn more.

How do I add an FTP user with a Linux command?
Q. I need to write a PHP script that automatically adds FTP users. I can use the system() function to run a Linux command, but I don't know how to create a new FTP user. Any help here?
I don't own the server, I've purchased a reseller plan.

A. When you say add an ftp user, I assume that you wouldn't want the person to be able to log in to a shell on the system. FTP users are just like any other linux user. Use the adduser(sometimes called useradd) command and pay attention to the --shell switch (set to /bin/false)



Nec Projector Review

Plastic Shed Reviews

Ati Graphic Reviews

Nurse Uniforms Reviews

Cabochons Reviews

Inflatable Water Slides Reviews

Barcode Scanner Reviews

No comments:

Post a Comment