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.
Related Unix and Linux Help articles:
✔ Copy and Paste from the Mac OS X Command Line?
I am constantly running commands in Terminal.app on my MacBook and then copying and pasting the results into email messages or documents. Yes,...✔ Shell script to convert lowercase to title case?
As part of a project I'm working on, I find myself deep in a Linux shell script, needing to have a subroutine that...✔ Can I script renaming files based on an XML data map?
I have a folder full of files which are named with four digits and a file extension e.g. 0312.file and an XML-file describing...✔ Test for valid numbers in a Bash shell script?
In a different discussion on this site [see Redirecting input in a shell script] a visitor commented that "I was too busy trying...✔ Review: iSSH for the iPad/iPhone
If you're running an online business like I am, there are times when you need to connect and log in to the server...
Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
I do have a comment, now that you mention it!
Check This Out Too...
Look for Answers
All Our Categories
Apple iPad Help
Articles and Reviews
Auctions and Online Shopping
Blogs and Blogging
Building Web Site Traffic
Business and Management
Computer and Internet Basics
d) None of the Above
Google Gmail Help
Google Plus Help
Industry News and Trade Shows
iPhone and Cell Phone Help
iPod, Sony PSP and MP3 Player Help
Kindle Fire Help
Mac OS X Help
Pay Per Click (PPC) Advertising
Search Engine Optimization (SEO)
Shell Script Programming
Tech Support Video Help
The Writing Business
Twitter, LinkedIn and Social Network Help
Unix and Linux Help
Video Game Tips and Help
Windows PC Help
Find Me on Google+
ADT on G+