cat
print a filecat reads the files it is given, one after another, and writes them out. With one file that prints it on the terminal; with several it joins them end to end, which is where the name comes from: concatenate.
Right for a short file you want to see whole. For a long one, reach for less, head or tail instead.
At the terminal
Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.
What the numbered lines are telling you
No header, no decoration. This file holds one line: the machine’s host name.
Useful when an error message says "line 3", or when you want to point someone at a particular line.
cat writes part1 then part2; the > sends that to whole.txt instead of the screen. Nothing is printed.
$ marks the end of the line. The ^M before it is a Windows carriage return — the reason a script edited on Windows fails with "bad interpreter".
Switches
A switch changes how the command behaves. These are the ones used day to day; man cat lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.
-n- Number every output line.
-b- Number only the lines that are not blank.
-s- Squeeze: show a run of blank lines as a single blank line.
-A- Show all: mark line ends with $, tabs as ^I, and other invisible characters.
-E- Mark the end of each line with $ — shows up trailing spaces.
Variations worth knowing
The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.
cat /etc/os-releaseShows which distribution and version the machine runs.
cat > note.txtTypes straight into a new file. Finish with Ctrl+D on an empty line.
cat a.log b.log | grep errorSearches several files as if they were one.
less /var/log/syslogFor a long file: scroll with the arrow keys, search with /, quit with q.
In cybersecurity
cat prints exactly the bytes in the file, and a terminal acts on some of those bytes rather than showing them.
Printing a binary or a hostile text file can send control sequences that change the terminal’s title, colours or more. Use "cat -v" or less for anything untrusted.
Escape codes can hide lines when a script is printed with cat, so what you read is not what will run. Open it in an editor before piping it to a shell.
Ordinary file reads leave no trace by default. If a secret was readable, assume it was read.