LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 12-12-2012, 08:36 PM   #1
WhiteHotLoveTiger
Member
 
Registered: Jun 2012
Location: NB, Canada
Distribution: Slackware
Posts: 67

Rep: Reputation: 1
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?
 
Old 12-12-2012, 08:43 PM   #2
T3slider
Senior Member
 
Registered: Jul 2007
Distribution: Slackware64-14.0
Posts: 2,244

Rep: Reputation: 620Reputation: 620Reputation: 620Reputation: 620Reputation: 620Reputation: 620
`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.
Old 12-12-2012, 11:03 PM   #3
josiah
Member
 
Registered: May 2004
Distribution: Slackware
Posts: 46

Rep: Reputation: 23
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.
Old 12-13-2012, 02:03 AM   #4
Mark Pettit
Member
 
Registered: Dec 2008
Location: Cape Town, South Africa
Distribution: Slackware 14.1 64 Multi-Lib
Posts: 421

Rep: Reputation: 123Reputation: 123
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.
 
Old 12-13-2012, 02:22 AM   #5
zakame
Member
 
Registered: Apr 2012
Distribution: Debian, Ubuntu, Slackware
Posts: 121

Rep: Reputation: 42
Quote:
Originally Posted by Mark Pettit View Post
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/
 
Old 12-13-2012, 04:22 AM   #6
Mark Pettit
Member
 
Registered: Dec 2008
Location: Cape Town, South Africa
Distribution: Slackware 14.1 64 Multi-Lib
Posts: 421

Rep: Reputation: 123Reputation: 123
I'll resist the temptation, great that it is, to turn this into a Python vs Perl thread :-)
 
Old 12-13-2012, 05:23 AM   #7
Didier Spaier
Senior Member
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slackware{,64}-{14.1,current} on a Lenovo Thinkpad T61 6457-4XG
Posts: 4,030

Rep: Reputation: 968Reputation: 968Reputation: 968Reputation: 968Reputation: 968Reputation: 968Reputation: 968Reputation: 968
Or the usual replacement for cat:
Code:
awk '{print}' <file>
 
Old 12-13-2012, 05:55 AM   #8
273
Senior Member
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64&i386, Raspbian Wheezy, various VMs
Posts: 3,228

Rep: Reputation: 759Reputation: 759Reputation: 759Reputation: 759Reputation: 759Reputation: 759Reputation: 759
Quote:
Originally Posted by Mark Pettit View Post
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.
 
Old 12-13-2012, 06:27 AM   #9
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 2,034

Rep: Reputation: 519Reputation: 519Reputation: 519Reputation: 519Reputation: 519Reputation: 519
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.
 
Old 12-13-2012, 06:56 AM   #10
Mark Pettit
Member
 
Registered: Dec 2008
Location: Cape Town, South Africa
Distribution: Slackware 14.1 64 Multi-Lib
Posts: 421

Rep: Reputation: 123Reputation: 123
Quote:
Originally Posted by 273 View Post
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".
 
Old 12-13-2012, 01:22 PM   #11
WhiteHotLoveTiger
Member
 
Registered: Jun 2012
Location: NB, Canada
Distribution: Slackware
Posts: 67

Original Poster
Rep: Reputation: 1
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...
 
  


Reply

Tags
source


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored terminal commands? Cinnamint Linux - Newbie 6 07-06-2012 02:07 AM
tee command source code? mdfakkeer Linux - Software 2 02-18-2010 04:28 AM
Where are my commands stored? ifeatu Linux - Newbie 9 10-06-2008 11:08 AM
commands stored into variables? benne Programming 2 11-15-2004 07:20 PM
Editing stored Terminal commands ShaanAli Linux - Software 2 01-13-2004 07:55 AM


All times are GMT -5. The time now is 07:38 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration