The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group


cat - concatenate and print files


cat [-u][file ...]


The cat utility reads files in sequence and writes their contents to the standard output in the same sequence.


The cat utility supports the XBD specification, Utility Syntax Guidelines  .

The following option is supported:

Write bytes from the input file to the standard output without delay as each is read.


The following operand is supported:
A pathname of an input file. If no file operands are specified, the standard input is used. If a file is "-", the cat utility will read from the standard input at that point in the sequence. The cat utility will not close and reopen standard input when it is referenced in this way, but will accept multiple occurrences of "-" as a file operand.


The standard input is used only if no file operands are specified, or if a file operand is "-". See the INPUT FILES section.


The input files can be any file type.


The following environment variables affect the execution of cat:
Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
If set to a non-empty string value, override the values of all the other internationalisation variables.
Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments).
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
Determine the location of message catalogues for the processing of LC_MESSAGES .




The standard output will contain the sequence of bytes read from the input files. Nothing else will be written to the standard output.


Used only for diagnostic messages.






The following exit values are returned:
All input files were output successfully.
An error occurred.




The -u option has value in prototyping non-blocking reads from FIFOs. The intent is to support the following sequence:

mkfifo foo
cat -u foo > /dev/tty13 &
cat -u > foo

It is unspecified whether standard output is or is not buffered in the default case. This is sometimes of interest when standard output is associated with a terminal, since buffering may delay the output. The presence of the -u option guarantees that unbuffered I/O is available. It is implementation-dependent whether the cat utility buffers output if the -u option is not specified. Traditionally, the -u option is implemented using the equivalent of the XSH specification setvbuf() function.


The following command:

cat myfile

writes the contents of the file myfile to standard output.

The following command:

cat doc1 doc2 > doc.all

concatenates the files doc1 and doc2 and writes the result to doc.all.

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

cat doc doc.end > doc

causes the original data in doc to be lost.

The command:

cat start - middle - end > file

when standard input is a terminal, gets two arbitrary pieces of input from the terminal with a single invocation of cat. Note, however, that if standard input is a regular file, this would be equivalent to the command:

cat start - middle /dev/null end > file

because the entire contents of the file would be consumed by cat the first time "-" was used as a file operand and an end-of-file condition would be detected immediately when "-" was referenced the second time.





UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]