NAME
cat —
concatenate files
SYNOPSIS
cat |
[-us]
[-n|-b]
[-TEv] [-teA]
[file]… |
DESCRIPTION
Copies each file (standard input stream if "-", the default), in order, to the standard output stream. In case of an input error, the file is skipped but processing continues.
OPTIONS
-u- Don't buffer output. Input is never buffered.
-s,--squeeze-blank- Replace runs of empty input lines with a single one.
-n,--number- Number lines from 1, separating them from the file contents with a tab.
-b,--number-nonblank- Likewise, but don't number empty lines.
-T,--show-tabs- Replace tab characters with "
^I". -E,--show-ends- Prepend newlines with a dollar
("
$"). -v,--show-nonprinting- Replace non-printable bytes
([0,
0x1F]
∪
[0x7F,
0xFF] -
{0x09
(tab),
0x0A
(newline)}) with their corresponding
"
^c" and "M-c" escapes (see STANDARDS, Escapes). -t-Tv-e-Ev-A,--show-all-TEv
EXIT STATUS
1 if a file couldn't be opened or read.
EXAMPLES
$echoechoed |catechoed
$echoabcdefg |split-b3$printf: |catxaa-xab-xac abc:defg$catxaa-xab-xac# teletype input boldedabcAA^DdefBB^Dg
$catform Groceries for February: Bananas 3.5kg $4.51 Kiwis 2kg $3.19 Call Siegfried to explain short! Bread $20.21$cat-sbteform 1 Groceries for February:$ $ 2 ^IBananas^I3.5kg^I$4.51$ 3 ^IKiwis^I2kg^I$3.19^ICall Siegfried to explain short!$ 4 ^IBread^I^I$20.21$
SEE ALSO
STANDARDS
Conforms to IEEE Std 1003.1-2024
(“POSIX.1”); -u is the only flag
specified by the standard. -nb,
-s, -tev compatible with
4BSD. Remaining flags (-TEA)
compatible with the GNU system.
Escapes
| 0x0 | 0x1 | 0x2 | 0x3 | 0x4 | 0x5 | 0x6 | 0x7 | 0x8 | 0x9 | 0xA | 0xB | 0xC | 0xD | 0xE | 0xF | |
| 0x00 | ^@ | ^A | ^B | ^C | ^D | ^E | ^F | ^G | ^H | ^I | ^K | ^L | ^M | ^N | ^O | |
| 0x10 | ^P | ^Q | ^R | ^S | ^T | ^U | ^V | ^W | ^X | ^Y | ^Z | ^[ | ^\ | ^] | ^^ | ^_ |
| 0x70 | ^? |
Above
0x80, the table
repeats but with M- prepended (i.e.
0xC1 is
M-A and
0x8A
— M-^J).
HISTORY
Appears in the first edition of the UNIX Programmer's Manual as cat(I):
NAMEcat -- concatenate and printSYNOPSIScat file1 ...
Version 3 AT&T UNIX adds the "-"-as-standard-input-stream behaviour. This can safely be considered fully-formed.
Version 7 AT&T UNIX sees a
rewrite in C with <stdio.h>,
and -u disabling buffering of the standard output
stream (considering it feeds getc() directly into
putchar() until end-of-file, this is a significant
penalty, but is, regardless, most likely decidedly slower than the previous
implementation, which mapped full-block
read(II)s onto
write(II)s). It also explicitly checks for, skips, and warns
about one of the input files also being bound to the standard output
stream.
3BSD uses a larger,
1024-byte
BUFSIZ, and hence output buffer.
4BSD introduces
-nb, -s,
and -tve — all as
today.
4.3BSD sees a fast read(2)/write(2) path if no flags were specified.
Programmer's Workbench (PWB/UNIX),
instead, sees -s, silencing errors, and a re-write
in terms of
read(2)/write(2). Oddly, AT&T System III
UNIX inherits this -s into an
Version 7 AT&T UNIX base.
AT&T System V
Release 2 UNIX also sees -tve, except
-te require -v to activate,
-t also controls
0x12 (form feed),
and M-^J (newline + high bit) is
M-$<newline>. The former can be attributed to
implementing according to the 4BSD manpage, which
erroneously implies the -v requirement. The latter
only to low QoI. Without -v, a block-wise
read(2)/write(2) copy is performed.