On this page
reference
1 min read
cat
cat prints the contents of files. Its name is short for "concatenate" — given several files, it prints them one after another, as a single stream.
cat [options] [file...]
$ cat notes.txt
$ cat part1.txt part2.txt part3.txt > whole.txt
With no file — or with the name - — cat reads standard input, which is what makes it useful in a pipeline or for capturing typed input into a file.
Plain use
Most of the time cat is run with no options at all: it copies its input to its output, byte for byte, unchanged. The options exist for the times you want to see something about the text that is normally invisible, or to adjust spacing and numbering.
Numbering lines
| Option | Effect |
|---|---|
-n, --number |
Number every output line. |
-b, --number-nonblank |
Number only the non-empty lines. Overrides -n. |
Making invisible characters visible
These options reveal characters that normally print as nothing, or as whitespace — useful when a file is not behaving and you suspect a stray tab or control character.
| Option | Effect |
|---|---|
-E, --show-ends |
Print a $ at the end of each line, so trailing spaces become visible. |
-T, --show-tabs |
Print tab characters as ^I instead of as whitespace. |
-v, --show-nonprinting |
Print control and other non-printing characters using ^ and M- notation (leaving newline and tab as they are). |
-e |
Shorthand for -vE. |
-t |
Shorthand for -vT. |
-A, --show-all |
Shorthand for -vET — show ends, tabs, and all non-printing characters at once. |
Adjusting spacing
| Option | Effect |
|---|---|
-s, --squeeze-blank |
Collapse runs of blank lines into a single blank line. |
Exit status
| Code | Meaning |
|---|---|
0 |
Every file was printed. |
1 |
A file could not be read. |
See also
Peios Learn
Built with Trail