Cat Command

James Gray james at grayonline.id.au
Wed Mar 15 03:07:22 UTC 2006


On Wed, 15 Mar 2006 01:41 pm, Lord Sauron wrote:
> Back in the /dev/null discussion there was some talk of the "cat"
> command (or something like that).  What's that?  I'm not familiar with
> that and I lost my "Linux in a Nutshell" book about a week ago.  I
> suspect it's hiding behind my other books on my desk, but I haven't
> looked yet.

"man cat" will give you details.  FWIW "cat" is short for "catenate".  So it 
simply displays the content of a list of files to STDOUT.  It displays the 
files in the order they're listed on the command line.  So:
cat file1.txt file2.txt
will display the content of file1.txt followed immediately by file2.txt's 
content.  It's handy if you have two files that are logically one piece of 
information, like "header.txt" and "body.txt" to form a single document :)

A lot of my stuff has the GPL license info at the top so I can prepend that 
all my source code like this:
$ ls
main.cpp
header.h
classes.h
GPL.txt

$ for $FILE in main.cpp header.h classes.h
do
cat GPL.txt $FILE > $FILE.new
done

Voila!  All my sources now have the GPL.txt file prepended to them and the new 
files have ".new" extension (ie, "main.cpp.new" etc.).  See how it works?

BTW, about this "/dev/null" thing, cat-ing something to /dev/null does nothing 
except give you the return value of cat. eg,
cat non-existant_file.txt > /dev/null ; echo $?
or,
cp $SRC $DEST 2>&/dev/null ; echo $?

This is handy in scripts etc. to trap errors from commands without having to 
interpret their output.

> Also, I started a blog about my adventures in learning more about
> Linux.  It's at www.thedarkesttower.blogspot.com in case anybody's
> interested.

Cool - I'll check it out later :)

Cheers,

James
-- 
Opportunities are usually disguised as hard work, so most people don't
recognize them.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/kubuntu-users/attachments/20060315/709b0530/attachment.sig>


More information about the kubuntu-users mailing list