The cat command reads files in sequence and writes them to standard output. cat has no effect on the sequence and format of the characters in the files.
If you name more than one file when calling cat, these files are output sequentially in the specified order.
If you do not name a file, cat reads from standard input.
Syntax
cat[ -s][ -u][ file...] |
No option specified: Output is buffered in BUFSIZ-byte blocks. The value of BUFSIZ is governed by the machine you are working on. It is defined in the file /usr/include/stdio.h and may be 8192 bytes. If the files named on the command line do not exist, cat tells you that it cannot open them.
Messages reporting that files do not exist are suppressed.
Output without buffering, one byte at a time.
Name of the file that is to be printed. You may specify more than one file. If you use a dash as the name for file, cat reads from standard input. file not specified: Caution! Redirecting the output of cat to one of the files being read will result in the loss of that file’s original contents. In the following command, for example, the contents of file1 are lost:
|
Error
You have no write permission for the output file out_file or for the directory which contains out_file.
You have no read permission for the input file in_file. |
Locale
The following environment variables affect the execution of cat: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE 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). LC_CTYPE governs character classes, character conversion (shifting) and the behavior of character classes in regular expressions. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. |
Example 1
Concatenate and redirect the output of two files:
|
Example 2
Display the contents of file1
Now write two lines of text into file2.
Terminate input with CTRL+C or @@d depending on the terminal type used. Now move the contents of file1 and file2 to file3, add two lines from standard input, and then print the contents of file3.
Terminate input with CTRL+C or @@d depending on the terminal type used.
|
See also
cp, pr |