Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

cat - concatenate and print files

&pagelevel(4)&pagelevel

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.

-s

Messages reporting that files do not exist are suppressed.

-u

Output without buffering, one byte at a time.

file

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:
cat reads from standard input.

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:

cat file1 file2 file3 > file1

Error

cat >out_file out_file: cannot create

You have no write permission for the output file out_file or for the directory which contains out_file.


cat in_file cat: cannot open in_file: Permission denied

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:

$ echo Monday Tuesday Wednesday >file1
$ echo Thursday Friday Saturday >file2
$ cat file1 file2 > file3
$ cat file3
Monday Tuesday Wednesday
Thursday Friday Saturday

Example 2

Display the contents of file1

$ cat file1
In Xanadu did Kubla Khan
A stately pleasure dome decree:
Where Alph, the sacred river, ran

Now write two lines of text into file2.

$ cat > file2
Through caverns measureless to man
Down to a sunless sea.

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.

$ cat file1 file2 - > file3
For he on honey dew hath fed
And drunk the milk of paradise.

Terminate input with CTRL+C or @@d depending on the terminal type used.

$ cat file3
In Xanadu did Kubla Khan
A stately pleasure dome decree:
Where Alph, the sacred river, ran
Through caverns measureless to man
Down to a sunless sea.
For he on honey dew hath fed
And drunk the milk of paradise.

See also

cp, pr