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 #

OptionEffect
-n, --numberNumber every output line.
-b, --number-nonblankNumber 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.

OptionEffect
-E, --show-endsPrint a $ at the end of each line, so trailing spaces become visible.
-T, --show-tabsPrint tab characters as ^I instead of as whitespace.
-v, --show-nonprintingPrint control and other non-printing characters using ^ and M- notation (leaving newline and tab as they are).
-eShorthand for -vE.
-tShorthand for -vT.
-A, --show-allShorthand for -vET — show ends, tabs, and all non-printing characters at once.

Adjusting spacing #

OptionEffect
-s, --squeeze-blankCollapse runs of blank lines into a single blank line.

Exit status #

CodeMeaning
0Every file was printed.
1A file could not be read.

Edit this page