The cat command in Linux
cat (concatenate) prints the contents of files to the terminal. For a quick look at a small file it is the fastest tool there is; its original purpose — joining several files into one stream — is still what the name refers to. For long files, a pager like less is more comfortable, since cat dumps everything at once.
How cat works
cat is the minimal Unix program: open each argument, read blocks, write them to standard output, repeat. It does not parse, interpret or transform anything — which is exactly why it is the universal glue. Concatenation is not a feature added to cat; it is what the read-write loop naturally does when handed several files.
The interesting behavior is in the plumbing around it. When stdout is a terminal, output appears line by line; when it is a pipe or file, the C library switches to block buffering for throughput. And cat with no arguments reads standard input — the property that makes cat > file into an improvised editor and lets it sit in the middle of pipelines.
Syntax
cat [OPTIONS] [FILE...] Common options
| Option | What it does |
|---|---|
-n | Number every output line. |
-b | Number only non-empty lines. |
-s | Squeeze consecutive blank lines into one. |
-A | Show non-printing characters (tabs as ^I, line ends as $). Useful for debugging whitespace. |
How to use cat: examples
$ cat notes.txt Print the whole file to the terminal.
$ cat -n script.sh Print with line numbers — handy when an error message references a line.
$ cat part1.txt part2.txt Print several files one after another: this is the actual "concatenate".
$ cat part1.txt part2.txt > combined.txt Join files into a new one by redirecting the output.
$ cat notes.txt | grep coffee Pipe file contents into another command — though grep coffee notes.txt does the same with one process fewer.
Real-world use cases for cat
Quick config inspection
cat /etc/os-release, cat ~/.ssh/config, cat package.json — for any file under a screenful, cat is the fastest possible viewer: no pager to quit, output stays in your scrollback for reference while you type the next command.
Assembling split files
Large files sometimes travel in pieces (data.csv.part1, part2…). cat data.csv.part* > data.csv concatenates them back in glob order — the literal, original purpose of the command, still useful for log consolidation and chunked downloads.
Try cat yourself
This is a live sandbox with a small filesystem (documents/, notes.txt,
backup.sh…). Nothing you do here can break anything — experiment freely.
Try: cat notes.txt
Pro tips and common mistakes
- cat -A exposes invisible characters: tabs as ^I, Windows line endings as ^M$. When a config "looks right but doesn't work", this often finds the culprit.
- Heredocs beat multiple echos for writing small files in scripts: cat > file <<EOF … EOF.
- Useless-use-of-cat: cat file | grep x spawns an extra process; grep x file does the same. Harmless interactively, but worth knowing.
- For JSON, pipe through a formatter: cat data.json | python3 -m json.tool (or jq) makes it readable.
Frequently asked questions about cat
What does cat stand for?
Concatenate. The command was designed to join files together; printing a single file is just the special case of concatenating one file to your screen.
When should I use less instead of cat?
For anything longer than a screenful. less lets you scroll, search with /, and quit with q, without flooding your terminal.
How do I create a file with cat?
Run cat > newfile.txt, type your content, then press Ctrl+D to finish. The shell writes everything you typed into the file.
Related commands
Find lines matching a pattern in files or piped input — the workhorse of text search.
echoPrint text and variables, and write or append to files with > and >>.