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

OptionWhat it does
-nNumber every output line.
-bNumber only non-empty lines.
-sSqueeze consecutive blank lines into one.
-AShow 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

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.

Things people do with cat

Search with grep ignoring case

Make grep match Error, ERROR and error with one option.

Search Bash command history

Find a command you ran before using history, reverse search and grep.

List hidden files in Linux

Use ls to show hidden files and directories, including .env and .git.

Count lines in a Linux file

Count lines, words and bytes with wc, with useful variations for logs and source files.

Errors you may hit with cat

bad interpreter: No such file or directory

Windows line endings make the shebang point at an interpreter that does not exist.

Related commands

grep

Find lines matching a pattern in files or piped input — the workhorse of text search.

echo

Print text and variables, and write or append to files with > and >>.

Want to build real fluency? The interactive course takes you through cat and every other essential command with guided, checked exercises.