CAT(1)

User Commands  ·  concatenate files and print on the standard output

NAME

cat — concatenate files and print on the standard output.

The cat utility is one of the oldest and most beloved tools in the Unix universe. Its name is short for concatenate, and despite the deceptive simplicity of that single idea, generations of system administrators, developers, and curious newcomers have leaned on it daily. Few commands are typed as often, and even fewer are understood as shallowly — for behind its three innocent letters lies a long and storied tradition.

SYNOPSIS

cat [OPTION]... [FILE]...

In the common case you simply hand cat a list of files and it pours their contents, in order, onto your terminal. With no file given — or when the file is a single dash - — it reads from the standard input, which makes it a natural building block in pipelines and a friendly companion to the keyboard.

DESCRIPTION

Concatenate FILE(s) to standard output. This sentence, terse as it is, hides an entire philosophy of computing. The Unix tradition prizes small tools that do one thing well and that speak a common language — streams of bytes — so that they may be joined together like words in a sentence. cat is perhaps the purest expression of that idea: it takes whatever you give it and faithfully passes it along, asking nothing and assuming little.

Consider, for a moment, the humble act of reading a file. You could open an editor, navigate menus, and wait for a window to render. Or you could type three letters, press Enter, and watch the contents stream past instantly. Multiply that small saving across thousands of invocations a day, across millions of practitioners around the world, and you begin to appreciate why a tool this modest has endured for half a century without meaningful change.

It is also worth dwelling on what cat does not do. It does not paginate. It does not wrap intelligently. It does not interpret your files or pretty-print them. This restraint is a feature, not an oversight. By refusing to be clever, cat remains predictable, and predictability is the bedrock upon which composable systems are built. When you need cleverness, you reach for less, head, tail, or a dozen other specialists — and you connect them to cat with a pipe.

"Cats are connoisseurs of comfort." — and so too is the command that bears their abbreviated name, content to sit quietly in your pipeline until the moment it is needed.

OPTIONS

The following options modify the behaviour of cat. Most of the time you will use none of them, but on the rare occasion that you need to peer into the invisible structure of a file — its tabs, its line endings, its non-printing characters — these flags become indispensable.

-A, --show-all
Equivalent to -vET. Reveals everything that would otherwise hide in plain sight.
-b, --number-nonblank
Number non-empty output lines, overriding -n.
-e
Equivalent to -vE.
-E, --show-ends
Display a $ at the end of each line, so trailing whitespace can no longer hide.
-n, --number
Number all output lines, beginning at one.
-s, --squeeze-blank
Suppress repeated empty output lines, collapsing whitespace into a single breath.
-t
Equivalent to -vT.
-T, --show-tabs
Display TAB characters as ^I.
-v, --show-nonprinting
Use ^ and M- notation, except for LFD and TAB.
--help
Display a help message and exit.
--version
Output version information and exit.

EXAMPLES

The examples below are intentionally ordinary — that is precisely the point.

# Print a single file
cat notes.txt

# Concatenate several files into one
cat chapter1.txt chapter2.txt chapter3.txt > book.txt

# Number every line of a source file
cat -n server.js

# Reveal hidden tabs and line endings
cat -A config.ini

# Read from standard input until Ctrl-D
cat

Each of these incantations is small, but together they sketch the working rhythm of life at the command line: glance at a file, glue a few together, peek beneath the surface, and move on. The tool fades into the background, and that quiet invisibility is the highest compliment a Unix utility can earn.

HISTORY

A cat command appeared in the very first edition of Unix, and it has accompanied the operating system — and its many descendants — ever since. Over the decades the implementation has been rewritten, standardised, and ported to nearly every platform imaginable, yet its essential character has remained untouched. There is a certain poetry in that continuity: a tool so simple that it never needed to change, in an industry that changes relentlessly.

To learn cat, then, is to learn a small piece of computing history that is still alive and still useful today. Read on, experiment freely, and let the stream carry you.