| This article includes a list of references, related reading or external links, but its sources remain unclear because it lacks inline citations. Please improve this article by introducing more precise citations where appropriate. (February 2008) |
The cat command is a standard Unix program used to concatenate and display files. The name is from catenate, a synonym of concatenate.
Contents |
The Single Unix Specification specifies the behavior that the contents of each of the files given in sequence as arguments will be written to the standard output in the same sequence, and mandates one option, -u, where each byte is printed as it is read.
If the filename is specified as -, then cat will read from standard input at that point in the sequence. If no files are specified, cat will read from standard input entered.
A typical interactive use of cat is to display a short file to the screen, the equivalent of the MS-DOS command "type":
cat README.txt
A more useful use of cat is to output the contents of two files, typically redirected to an output file:
cat Morning.txt Evening.txt > Day.txt
Experienced users often use cat to create a small file from the terminal, the equivalent of the MS-DOS "copy con":
cat > shorty.txt
Both the BSD versions of cat (as per the OpenBSD manpage) and the GNU coreutils version of cat specify the following options:
The Jargon File version 4.4.7 lists this as the definition of cat:
Among Unix fans, cat(1) is considered an excellent example of user-interface design, because it delivers the file contents without such verbosity as spacing or headers between the files, and because it does not require the files to consist of lines of text, but works with any sort of data. Among Unix critics, cat(1) is considered the canonical example of bad user-interface design, because of its woefully unobvious name. It is far more often used to blast a single file to standard output than to concatenate two or more files. The name cat for the former operation is just as unintuitive as, say, LISP's cdr. |
UUOC (from comp.unix.shell on Usenet) stands for "Useless Use of cat". As received wisdom on comp.unix.shell observes "The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process." Nevertheless one sees people doing
cat file | some_command and its args .....
instead of the equivalent and cheaper
<file some_command and its args ...
or (equivalently and more classically)
some_command and its args ... <file
Without two named files cat is a useless use of cat. A UUOC campaign will eliminate the inefficiency from shell scripts by using redirection instead. However, cat with one named file is safer where human error is a concern—one wrong use of the default[1] redirection symbol ">" instead of "<" (often adjacent on keyboards) will permanently delete[2] the file you were just needing to read.
Since 1995, occasional awards for UUOC have been given out, usually by Perl programmer Randal L. Schwartz. There is a web page devoted to this and other similar awards. In British hackerdom the activity of fixing instances of UUOC is sometimes called demoggification.[3]
The equivalent command in the VMS, CP/M, DOS, OS/2, and Microsoft Windows operating system command shells is type.
split, a command that splits a file into pieces which cat can then rejoin.tac, a similar tool which concatenates files backwards.cat: compare two files – Commands & Utilities Reference, The Single UNIX® Specification, Issue 7 from The Open Groupcat(1): concatenate and write files – GNU Coreutils referencecat(1): concatenate and print files – OpenBSD General Commands Manualcat(1) – FreeBSD General Commands Manualcat(1) – Plan 9 General Commands Manual
|
||||||||||||||||||||||||||
stock | retire | vm
Why are we here?
All text is available under the terms of the GNU Free Documentation License
This page is cache of Wikipedia. History