kmail.at
← learning

linux · difficulty ◆

cat — concatenate files

Oldest trick in the book: dump a file, then join a few more onto it.

2026-08-18 · 4 min read

$ cat

What it does

cat reads one or more files and writes their contents to standard output, one after another. With a single file it just prints it — which is why most people learn cat as 'print a file to the screen'. But the name is the whole story: cat is short for 'concatenate'. Its real job is joining files together, and printing one to the terminal is just the degenerate case. That dual nature is why it feels trivial and is everywhere at once.

Why it matters

cat is the atomic unit of Unix text handling. Piping cat into another tool (cat file | grep pattern) is the most common way to feed a file's contents into a pipeline. It is also how you quickly inspect a config or log without opening an editor. And because cat writes to standard output, redirecting it is how you merge or copy files without a dedicated copy tool: cat a.txt b.txt > combined.txt. Learning cat is really learning the pipe-and-redirect model that powers everything else.

Example

$ cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.2 LTS (Noble Numbat)"
ID=ubuntu
ID_LIKE=debian

The simplest use: print a file straight to the terminal.

$ cat notes1.txt notes2.txt > notes-all.txt
$ cat notes1.txt notes2.txt > notes-all.txt
$ wc -l notes-all.txt
14 notes-all.txt

cat concatenates the two files into one, using > to redirect the combined output to a new file.

$ cat -n /etc/hosts
     1  127.0.0.1   localhost
     2  127.0.1.1   my-machine
     3
     4  # The following lines are desirable for IPv6 capable hosts
     5  ::1         ip6-localhost ip6-loopback

-n numbers every line as it prints, handy for citing a specific line in a config or log.

Common flags

-n
number all output lines
-b
number only non-blank lines
-A
show all — equivalent to -vET (reveal hidden characters)
-E
show $ at the end of each line
-s
suppress repeated empty output lines
-T
show tab characters as ^I

History

Origin

cat has been in Unix since the very first edition, released in 1971. It is one of the handful of commands that shipped on day one, and its name is simply a contraction of 'concatenate'. Over half a century later it is still the standard, and nearly every Unix and Linux system ships a version of it — on GNU systems as part of coreutils, where its current version has been maintained continuously for decades.

Fun fact

cat is the reason we still say 'piping' — the phrase comes from the shell's pipe symbol, |, which was designed to connect cat's output to another program's input. And there is a playful echo of the tool in the name of its exact opposite: tac, which is cat spelled backwards and prints files in reverse line order.

Related commands

← all learning