LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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: 73

Rep: Reputation: 2
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.1
Posts: 2,367

Rep: Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843
`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: 72

Rep: Reputation: 42
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 15.0
Posts: 619

Rep: Reputation: 299Reputation: 299Reputation: 299
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
Location: Philippines
Distribution: Debian, Ubuntu, Slackware
Posts: 295

Rep: Reputation: 181Reputation: 181
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 15.0
Posts: 619

Rep: Reputation: 299Reputation: 299Reputation: 299
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
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,063

Rep: Reputation: Disabled
Or the usual replacement for cat:
Code:
awk '{print}' <file>
 
Old 12-13-2012, 05:55 AM   #8
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
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: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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 15.0
Posts: 619

Rep: Reputation: 299Reputation: 299Reputation: 299
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: 73

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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration