cat
PURPOSE
Concatenates or displays files.
SYNOPSIS
cat [ -u ] [ -s ] file ...
DESCRIPTION
The cat command reads each file in sequence and writes it
to standard output. If you do not specify file or
specify - (minus) instead of a file, cat reads from
standard input.
Warning: Do not redirect output to one of the input
files using the ">" redirection symbol. If you do this,
you will lose the original data in the input file because
the shell truncates it before cat can read it (see "sh").
FLAGS
-s Does not display a message if cat cannot find an
input file.
-u Does not buffer output.
EXAMPLES
1. To display a file at the work station:
cat notes
This displays the data in the file "notes". If the
file is more than about 23 lines long, some of it
will scroll off the screen. To list a file one page
at a time, use the pg command. (See "pg" for
details.)
2. To concatenate several files:
cat section1.1 section1.2 section1.3 >section1
This creates a file named "section1" that is a copy
of "section1.1" followed by "section1.2" and
"section1.3".
3. To suppress error messages about files that do not
exist:
cat -s section2.1 section2.2 section2.3 >section2
If "section2.1" does not exist, this concatenates
"section2.2" and "section2.3". The result is the
same if you do not use the -s, except that cat dis-
plays the error message:
cat: cannot open section2.1
You may want to suppress this message with the -s
flag when you use the cat command in shell proce-
dures.
4. To append one file to the end of another:
cat section1.4 >>section1
This appends a copy of "section1.4" to the end of
"section1". The ">>" appends data to the end of
"section1". If you want to replace the file, use the
">". For more details, see "Redirection of Input and
Output."
5. To add text to the end of a file:
cat >>notes
Get milk on the way home
Ctrl-D
"Get milk on the way home" is added to the end of
"notes". The cat command does not prompt; it waits
for you to enter text. Press Ctrl-D to indicate you
are finished.
6. To concatenate several files with text entered from
the keyboard:
cat section3.1 - section3.3 >section3
This concatenates "section3.1", text from the key-
board, and "section3.3".
7. To concatenate several files with output from another
command:
li | cat section4.1 - >section4
This copies "section4.1", and then the output of the
li command to the file "section4".
RELATED INFORMATION
The following commands: "cp," "pr," and "sh."