Conceptually equivalent to DOS "type", but the name is taken from its ability to con-CAT-enate multiple files to stdout. Few people bother to look at the man page, which is too bad, because it often has useful optional flags - the Linux and BSD versions are particularly feature rich.
"Useless use of cat award" is often sarcastically given to people who post things like:
cat file | more
because all that is needed is "more file". However, although perhaps wasteful (why would you care nowadays?), consider the situation where you have typed "cat file" and then realized that the display has run off your screen. If running bash, a simple up arrow and "| more" is easier than doing it "right". I confess to doing something similar fairly frequently. Every time I do it, I automatically think "useless use of cat..", but of course it really isn't.
People sometimes mistakenly invoke that "award" when someone does "cat *.c | grep something". That's NOT the same as "grep something *.c" and may be exactly what you need to do for the results you want.
"cat -e" is useful for showing where lines actually end - it adds a $ symbol to the end of each line. "cat -v" shows non-printing characters, "cat -t" shows tabs. "cat -s" can be useful in scripts as it is silent if what you asked it to cat doesn't exist.
"cat -u" is unbuffered cat, and doesn't buffer its output. This is seldom necessary, but if you are reading a FIFO it might help.
Got something to add? Send me email.
More Articles by Tony Lawrence © 2011-06-29 Tony Lawrence
Why bother with subroutines when you can type fast? (Vaughn Rokosz)
Printer Friendly Version
cat Copyright © October 2003 Tony Lawrence
Have you tried Searching this site?
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.
Contact us
Printer Friendly Version