[Previous] [Contents] [Next]

cat

Concatenate and print files (POSIX)

Syntax:

cat [-c] [-u] [file...]

Options:

-c
Compress each sequence of multiple newline characters into a single newline character.
-u
Write unbuffered output. Data from the input file(s) is written to the standard output without delay as each file is read.
file
The pathname of an input file. If no files are specified, the standard input is used. If a file is the dash character (-), cat reads from the standard input at that point in the sequence.

Description:

The cat utility reads files in the order you specify and writes the contents of these files to the standard output.

Examples:

Write the contents of the file myfile to the standard output:

cat myfile

Concatenate the files doc1 and doc2 and write the result to the doc.all file:

cat doc1 doc2 > doc.all

Append the contents of node 1's /.licenses file to node 5's /.licenses file:

cat //1/.licenses  >>//5/.licenses

Files:

The cat utility writes the contents of the files named on the command line (which may include the standard input) to the standard output.

If an error is encountered (e.g. in attempting to open or read a file), a diagnostic message will be written to the standard error.

Exit status:

0
All input files were output successfully.
>0
An error occurred.

Caveats:

Because of the shell language mechanism used to perform output redirection, a command such as:

cat doc doc.end > doc

causes the original data in doc to be lost. The file doc would be opened for write by the shell, and therefore truncated to zero length, before cat was executed.

See also:

cp, head, tail


[Previous] [Contents] [Next]