Overview
cat writes the contents of the files you name to standard output, in order. With no file, or with -, it copies standard input. Use it to view a short file, join files, or feed a pipeline.
Background
The name is short for concatenate: cat joins files and writes them to standard output. A cat utility appeared in Version 1 Unix, and Dennis Ritchie designed and wrote the first manual page, according to the FreeBSD and macOS manuals. Today the name covers GNU cat, the cat that macOS ships, and the cat applet in BusyBox. They agree on plain concatenation and the numbering example below, which ran on all three, and differ on options such as -A and -s.
Examples
Print a file:
cat notes.txt
Join two files, in the order given:
cat app.log notes.txt
Number every output line:
cat -n notes.txt
Mix standard input and a file; - stands for standard input:
echo 'from stdin' | cat - notes.txt
Copy a file by redirecting the output:
cat notes.txt > copy.txt
Options
-n
Number all output lines starting at 1. The number and a tab or spaces precede each line; exact
padding differs by implementation.
Common mistakes
Redirecting to a file you are also reading, as in cat notes.txt > notes.txt, empties the file before cat reads it. cat file | command is usually unnecessary: most commands read a file name or < redirection directly. For large files prefer a pager or head/tail.
Portability
Only the options listed here are in the Common examples. The Common examples were executed on GNU coreutils 9.11, macOS system tools, and BusyBox 1.37.0 (see the development guide for the exact check). Options such as -s, -A, -e, and -t are not uniform; check the installed manual.
References
Original explanations, with upstream documentation for further reading. FreeBSD references are comparison material, not a claim of Apple version equivalence.