Slackware This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
12-12-2012, 08:36 PM
|
#1
|
|
Member
Registered: Jun 2012
Location: New Broomstick
Distribution: Slackware
Posts: 32
Rep:
|
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?
|
|
|
|
12-12-2012, 08:43 PM
|
#2
|
|
Senior Member
Registered: Jul 2007
Distribution: Slackware64-14.0
Posts: 2,192
|
`cat` and `tee` are part of the coreutils package. The following command would tell you that:
Code:
grep -E "/(cat|tee)$" /var/log/packages/*
|
|
|
1 members found this post helpful.
|
12-12-2012, 11:03 PM
|
#3
|
|
Member
Registered: May 2004
Distribution: Slackware
Posts: 46
Rep:
|
Incidentally, the man or info page for either of them would make it clear that they're part of the coreutils package.
|
|
|
1 members found this post helpful.
|
12-13-2012, 02:03 AM
|
#4
|
|
Member
Registered: Dec 2008
Location: Cape Town, South Africa
Distribution: Slackware 14.0 64 Multi-Lib
Posts: 281
Rep:
|
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.
|
|
|
|
12-13-2012, 02:22 AM
|
#5
|
|
Member
Registered: Apr 2012
Distribution: Debian, Ubuntu, Slackware
Posts: 86
Rep:
|
Quote:
Originally Posted by Mark Pettit
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.
|
I'll agree to that, but for a different reason: GNU coreutils isn't exactly a good example of accessible C code. Take this gist comparing different implementations of echo(1), for example.
As for a Python reimplementation, I'd say Perl went ahead with that years ago.
Last edited by zakame; 12-13-2012 at 02:24 AM.
Reason: s/cat/echo/
|
|
|
|
12-13-2012, 04:22 AM
|
#6
|
|
Member
Registered: Dec 2008
Location: Cape Town, South Africa
Distribution: Slackware 14.0 64 Multi-Lib
Posts: 281
Rep:
|
I'll resist the temptation, great that it is, to turn this into a Python vs Perl thread :-)
|
|
|
|
12-13-2012, 05:23 AM
|
#7
|
|
Senior Member
Registered: Nov 2008
Location: Paris, France
Distribution: Slackware-14.0 on a Lenovo T61 6457-4XG
Posts: 2,788
|
Or the usual replacement for cat:
Code:
awk '{print}' <file>
|
|
|
|
12-13-2012, 05:55 AM
|
#8
|
|
Senior Member
Registered: Dec 2011
Location: UK
Distribution: Debian Sid + various in VMs.
Posts: 1,833
|
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.
|
|
|
|
12-13-2012, 06:27 AM
|
#9
|
|
Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 646
Rep: 
|
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.
|
|
|
|
12-13-2012, 06:56 AM
|
#10
|
|
Member
Registered: Dec 2008
Location: Cape Town, South Africa
Distribution: Slackware 14.0 64 Multi-Lib
Posts: 281
Rep:
|
Quote:
Originally Posted by 273
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".
|
|
|
|
12-13-2012, 01:22 PM
|
#11
|
|
Member
Registered: Jun 2012
Location: New Broomstick
Distribution: Slackware
Posts: 32
Original Poster
Rep:
|
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...
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:16 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|