
What capabilities does the "cat" command have?
A reader writes:
I had taken an intro course to UNIX a few years ago, but have found your book Teach Yourself Unix in 24 Hours MUCH more comprehensive and user-aware! The reader continues with a nice post-script: I think you book is quite a resource for introducing our people to UNIX. The Information Systems department here in our office has purchased 16 copies and distributed them to my colleagues. First off, thanks for the kind words about my book. It distills more years of working with the Unix command line than I want to think about (and yet, even this morning I spent two hours working with grep and vi through an ssh connection to my server). In terms of the cat command, it's really one of the simpler commands available on the command line in Unix/Linux and just dumps out the contents of the specified file to standard output. So by default, cat .login, for example, dumps the contents of the ".login" file to the screen. Once you start looking at file redirection in the shell, however, then you find out that cat becomes a considerably more powerful utility. For example, if I typed in cat .login > my.login then I would have accomplished essentially the same functionality as a file copy command (e.g., cp). But since cat can accept multiple filenames, a classic use of the command is to merge a bunch of files into a single output filename: cat a.txt b.txt c.txt d.txt > merged.txt. Another quite common use of cat occurs in shell scripts, where it uses what us shell scripting programmers call here documents. These are a way to trick commands into thinking that you're redirecting input from a file, as in wc < inputfile when there's actually no file being fed to the command. The notation looks like this: << some end marker so if I wanted to find out what wc had to report about a paragraph of text, I could use: cat << EOF | wc This is a paragraph of text that we want to learn more about, so we're feeding it to the 'wc' command through use of a here document. EOFThe result of this would be that wc would report how many lines, words and characters were found in its standard input, e.g., the short paragraph of text fed to it through use of the here document. I hope that clears everything up! If not, please post a response and we can explore this topic further.
Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.
Categorized:
Unix and Linux Help
(Article 3757)
Tagged: Previous: Is there a venue for me to show off my HTML skills? Next: How do I change my Mac OS X hard drive icon? Subscribe!
Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader. See i am working on GRIB files (i.e) Grided Binary files.I have gone through a web site where it was me ntioned that if you use this command " cat > EOF " then you will be able to cat all the files there. So can you please let me know as to how this command works.. Posted by: Abhisek at April 25, 2007 1:15 AMhello sir, i understood how cat works, but dint get the last part cat <<EOF | wc thing.. And can i get the shell script of cat? Posted by: sandeep at November 14, 2007 11:31 PMI have a lot to say, but ...
I do have a comment, now that you mention it!
|
![]()
Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.
Help!
Subscribe to
Ask Dave Taylor!
Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.
Articles and Reviews
Auctions and Online Shopping Blogs and RSS Feeds Building Web site traffic Business and Management Cell Phones and Mobile Phones CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above HTML and CSS Mac OS X Help MySpace, Facebook, Twitter and Social Network Help Pay Per Click (PPC) Search Engine Optimization Shell Script Programming Sony PSP, MP3 Players, Etc. The Writing Business Unix and Linux Help Video Game Tips and Help Windows Help
Recent Entries
Join the List!
Book Links
|