Industry guru Dave Taylor offers free tech support on a wide variety of technical and business topics, including HTML, Apple iPhone, online advertising, Cascading Style Sheets, Web design, management, Unix, Linux, search engine optimization, online dating, Mac OS X, shell script programming and Microsoft Windows.

What does "cat -" do on the Unix command line?

Hello I would like to know the what exactly does cat - mean in Unix? I was recently reading through an article that mentioned this command and couldn't understand what it did.


Dave's Answer:

"cat" is the 'concatenate' program and its purpose is to display the contents of one or more file. Add the '-' flag, however, and you have it display the content of "standard input" or "stdin": in a pipe like:

tail myfile | cat -

It's basically a null operation, since this is no different than doing:

tail myfile

A lot of shell script authors use structures like this too:

cat - << EOF
for what we script programmers call a here document, but most times this can be accomplished in other ways that are more resource efficient on the system.

In general, the cat - command is sometimes useful for shell scripting, but in general usage you'll rarely, if ever, see it on a command line.



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Stumble Upon    

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

Note that "cat -" is basically "cat" anyway.

Posted by: monsieur at May 17, 2006 5:05 AM

hi
Please i will be very happy if you could please tell me what does Cat do in linux system

thanks

Posted by: John at January 10, 2008 12:16 AM

How do i subscribe to your website?

Posted by: Stephen at May 17, 2009 11:56 PM

I have something to say, now that you mention it, but ...
Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you for all your efforts on this Web site by buying you a cup of coffee!

I do have a comment, now that you mention it!











Remember personal info?


Please note that I will never send you any unsolicited email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.








Ask Dave Taylor: The iPhone App: Advertisement



Follow me on Twitter @DaveTaylor

Search
Find just the answers you seek from among our 2300+ free tech support articles by using our Lijit search engine.


Linux Journal: Free Issue!

Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Book Links
© 2002 - 2010 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.