Cat (Unix)

codice_1 is a standard Unix utility that reads files sequentially, writing them to standard output. The name is derived from its function to concatenate files.
History.
codice_1 was part of the early versions of Unix, e.g., Version 1, and replaced codice_3, a PDP-7 and Multics utility for copying a single file to the screen.
The version of codice_1 bundled in GNU coreutils was written by Torbjorn Granlund and Richard Stallman.
Usage.
The Single Unix Specification defines the operation of codice_1 to read files in the sequence given in its arguments, writing their contents to the standard output in the same sequence. The specification mandates the support of one option flag, "u" for unbuffered output, meaning that each byte is written after it has been read. Some operating systems, like the ones using GNU Core Utilities, do this by default and ignore the flag.
If one of the input filenames is specified as a single hyphen ("-"), then codice_1 reads from standard input at that point in the sequence. If no files are specified, codice_1 reads from standard input only.
The command-syntax is:
 cat [options] [file_names]
Options.
Example of some codice_1 options:
Use cases.
codice_1 can be used to pipe a file to a program that expects plain text or binary data on its input stream. codice_1 does not destroy non-text bytes when concatenating and outputting. As such, its two main use cases are text files and certain format-compatible types of binary files.
Concatenation of text is limited to text files using the same legacy encoding, such as ASCII. codice_1 does not provide a way to concatenate Unicode text files that have a Byte Order Mark or files using different text encodings from each other.
For many structured binary data sets, the resulting combined file may not be valid; for example, if a file has a unique header or footer, the result will spuriously duplicate these. However, for some multimedia digital container formats, the resulting file is valid, and so codice_1 provides an effective means of appending files. Video streams can be a significant example of files that codice_1 can concatenate without issue, e.g. the MPEG program stream (MPEG-1 and MPEG-2) and DV (Digital Video) formats, which are fundamentally simple streams of packets.
Unix culture.
Jargon file definition.
The Jargon File version 4.4.7 lists this as the definition of codice_1:
Useless use of cat.
"Useless use of cat" ("UUOC") is common Unix jargon for command line constructs that only provide a function of convenience to the user. In computing, the word "abuse", in the second sense of the definition, is used to disparage the excessive or unnecessary use of a language construct; thus, abuse of codice_1 is sometimes called "cat abuse". Example of a common codice_1 abuse is given in the award:
 cat filename | command arg1 arg2 argn
This can be rewritten using redirection of stdin instead, in either of the following forms (the first is more traditional):
Beyond other benefits, the input redirection forms allow "command" to perform random access on the file, whereas the codice_1 examples do not. This is because the redirection form opens the file as the stdin file descriptor which "command" can fully access, while the codice_1 form simply provides the data as a stream of bytes.
Another common case where codice_1 is unnecessary is where a command defaults to operating on stdin, but will read from a file, if the filename is given as an argument. This is the case for many common commands; the following examples
can instead be written as
A common interactive use of codice_1 for a single file is to output the content of a file to standard output. However, if the output is piped or redirected, codice_1 is unnecessary.
A codice_1 written with UUOC might still be preferred for readability reasons, as reading a piped stream left-to-right might be easier to conceptualize. Also, one wrong use of the redirection symbol ">" instead of "<" (often adjacent on keyboards) may permanently delete the content of a file, in other words clobbering, and one way to avoid this is to use codice_1 with pipes. Compare:
with:
 cat in | command | command2 > out
tac.
tac is a Linux command that allows viewing files line-by-line, beginning from the last line. (tac doesn't reverse the contents of each individual line, only the order in which the lines are presented.) It is named by analogy with codice_1.
Usage: