Free tech support / small logo


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.









Subscribe!
Never miss another Q&A article! Click to subscribe: Add to Google Reader Add to My Yahoo! Subscribe in NewsGator RDF XML
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.









Recent Entries


Search
I Need Help!
Need Help? Ask Dave Taylor!

Linux Journal: Free Issue!


© 2002 - 2012 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.