Vol. I · No. 46The command line sectionSat, 10 Oct 2026
Linux · reading files

cat

print a file

cat 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.

Prints
The whole file
start to finish, no paging
Joins
Several files
in the order they are named
Line numbers
-n
added on the left
Best for
Short files
a long one scrolls away

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.

user@netflow — bashcoreutils
$ cat /etc/hostname
1netflow
2$ cat -n /etc/hosts
1 127.0.0.1 localhost
2 127.0.1.1 netflow
3 192.168.1.20 fileserver
3$ cat part1.txt part2.txt > whole.txt
4$ cat -A deploy.sh | head -1
#!/bin/bash^M$
Illustrative session · names, sizes and dates are examples, and every address is from a documentation or private range
Reading the output

What the numbered lines are telling you

1
The file’s contents, and nothing else

No header, no decoration. This file holds one line: the machine’s host name.

2
-n numbers the lines

Useful when an error message says "line 3", or when you want to point someone at a particular line.

3
Two files joined into a third

cat writes part1 then part2; the > sends that to whole.txt instead of the screen. Nothing is printed.

4
-A shows what is normally invisible

$ 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-release

Shows which distribution and version the machine runs.

cat > note.txt

Types straight into a new file. Finish with Ctrl+D on an empty line.

cat a.log b.log | grep error

Searches several files as if they were one.

less /var/log/syslog

For 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.

Binary files and escape codes

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.

What a script really says

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.

Reading is logged nowhere

Ordinary file reads leave no trace by default. If a secret was readable, assume it was read.

Filed under

Reading files

Read alongside