[SOLVED] Where is the source for commands like 'cat' and 'tee' stored?
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Where is the source for commands like 'cat' and 'tee' stored?
In an effort to better understand my computer, I've started to poke around at things that I previously wasn't brave enough to look at, like the files in /etc/rc.d. I was really surprised that some of these files aren't all that complex or scary. I felt like I could understand most of what was going on. I've also started looking at the source for some of the programs that I use. However, I can't seem to find everything I'm looking for. I've looked through the different Slackware source directories, and searched a little through the kernel source, but I can't find the command "tee", or "cat". Are these part of larger packages with a different name, or am I just not looking hard enough?
To be honest, I'm not sure that you will learn a huge amount from the source code of those base utilities. They're all written in "c" - a very powerful language. But fraught with the most awful dangers. Unless you have a huge need to suddenly start coding in "c", your efforts will be better rewarded in learning something like Python. Both of those programs (cat/tee) could be rewritten in Python in less than 100 lines, considerably less than the original "c" sources.
To be honest, I'm not sure that you will learn a huge amount from the source code of those base utilities. They're all written in "c" - a very powerful language. But fraught with the most awful dangers. Unless you have a huge need to suddenly start coding in "c", your efforts will be better rewarded in learning something like Python. Both of those programs (cat/tee) could be rewritten in Python in less than 100 lines, considerably less than the original "c" sources.
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680
Rep:
Quote:
Originally Posted by Mark Pettit
Both of those programs (cat/tee) could be rewritten in Python in less than 100 lines, considerably less than the original "c" sources.
Isn't that a little misleading? I mean, I could write a program to "cat" in one word in BASH "cat". There still needs to be an underlying mechanism to do the job.
Also note - there are things "cat" can do that python isn't guaranteed to do.
You CAN use cat to copy files... unless those files are sparse.
You CAN use bash implement a cat... unless you need to ensure that the files are not altered (by line termination problems at a minimum)
You CAN implement cat in Python (or perl)... but it will run slower.
I've even seen ls implemented in "sh"... but it can't handle large directories...
And the last time I looked (many years ago now) cat only took about 100 lines of C (about half was the help text built in). Of course there is the runtime C library, but you have to use that even if you are using Perl or Python.
Just because something CAN be done, doesn't mean it should be done, especially in production.
Experimentation though - it's good for you. And you will learn a lot.
Isn't that a little misleading? I mean, I could write a program to "cat" in one word in BASH "cat". There still needs to be an underlying mechanism to do the job.
Well - not really. Remember Python has an excellent library system, much of which is a simple direct interface to the standard C library. But my point here was not to promote Python itself, but more to tell the OP that studying this particular codebase was not a good idea. To be honest, if we're making an academic exercise of learning code, then really the holy grail should be LISP. After 30 years of professional programming, I still aspire to try to learn LISP. I've programmed professionally in (mainframe) Assembler, Cobol (yugh) and "c" (10 years of that), and now for the last 10 years, in Python. And the more I program in Python, the less desire I have to program in anything else !
BTW - one of the underlying modules in Python that would do a cat/tee like implementation would be "shutils".
Thanks for all the responses. I appreciate hearing the different viewpoints and insights.
This is getting a off topic from my original question, but if I might respond to some of the comments about which languages to spend time learning more about:
I have a basic familiarity with both C and Python. I'd love to learn LISP. Everything I've read about it makes it sound very interesting. From a practical standpoint though, I feel I should focus on skills that can help me gain employment. Whenever I check job postings around the area where I live, there's tons of positions for Visual Basic and ASP.net positions, a few for java, C++, SQL, and javascript positions, the odd one for C developers, and anything else is pretty rare (this is a little subjective, as I don't tally the results or anything).
I worked for a couple years in a .Net shop. It paid the bills well enough, but I really longed to be using something else. Right now I've gone back to school to finish off my Bsc, and pretty well everything is java. I'm fine with java, but I really enjoy the odd class where we have to use C.
I know that I really enjoy using C. I know that I hate using Visual Basic. Even though it would be much easier for me to find work as a VB programmer, I know that I'd be much happier working as a C programmer.
So, I think it makes sense for me to spend reading though C code bases and practising my C coding skills, but I guess it would be more practical to boot up Windows, install Visual Studio and practice the other stuff...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.