cat command (Linux / bash / sh / zsh)
What it does
Concatenate files and write their contents to standard output. When people search for the cat command linux, they usually want cat's everyday flags, safe examples, and how it differs from related tools. Below you'll find syntax, options, and copyable examples for Bash/sh/zsh.
Concatenate files and write their contents to standard output.
Syntax
cat [OPTION]... [FILE]...
Common options
| Flag / option | Meaning |
|---|---|
| -n | Number every output line. |
| -b | Number nonblank lines only. |
| -A | Reveal tabs, line endings, and nonprinting characters. |
| -s | Collapse repeated blank lines. |
Practical examples
Read a file
cat README.md
Writes the complete file to the terminal.
Join parts
cat part1 part2 > complete.txt
Combines two files into a new file.
Inspect whitespace
cat -A data.txt
Makes hidden spacing characters visible.
Linux ↔ Windows equivalent
Closest match: Get-Content (Windows / PowerShell). Read file content or provider data as a stream of objects.
Common mistakes
- Using cat for a huge file and flooding the terminal; use less instead.
- Redirecting output to one of the input files, truncating it before cat reads it.
Related commands
- lessPage through text interactively without loading it all at once.
- headPrint the beginning of files or standard input.
- teeCopy standard input to standard output and one or more files.
- grepSearch text for lines matching a pattern.
- Where-ObjectFilter pipeline objects by property values or a script block predicate.
- Get-ContentRead file content or provider data as a stream of objects.
- echoWrite arguments and shell-expanded values to standard output.
- echoDisplay text or control command echoing in a batch script.
FAQ
What does cat do in Linux?
Concatenate files and write their contents to standard output.
How do I use cat from the terminal?
Start with `cat [OPTION]... [FILE]...`, then choose only the options needed for the task.
What is a practical cat example?
Try `cat README.md` — Writes the complete file to the terminal.
Can I use cat in a shell script?
Yes. cat works in Bash, sh, and Zsh, but scripts should handle quoting, errors, and command output explicitly.
Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.