cat – concatenate files and print to standard output

cat concatenates files and prints them to standard output. It’s the go-to tool for viewing small text files.
Synopsis
cat [OPTIONS] [FILE]...
Common Options
| Option | Description |
|---|---|
-n | Number all output lines |
-b | Number non-empty lines only |
-s | Squeeze multiple blank lines into one |
-A | Show all characters (equivalent to -vET) |
-E | Show $ at end of each line |
Examples
View a file
$ cat /etc/hosts
127.0.0.1 localhost
::1 localhost
Concatenate multiple files
$ cat header.txt body.txt footer.txt > document.txt
Number lines (all)
$ cat -n /etc/passwd | head -3
1 root:x:0:0:root:/root:/bin/bash
2 daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
3 bin:x:2:2:bin:/bin:/usr/sbin/nologin
Number lines (non-empty only)
$ cat -b file-with-blanks.txt
1 First line
2 Second line
3 Fourth line (blank line above not numbered)
Tips
- For large files, use less or more instead
- To reverse line order, use tac
- Create files quickly:
cat > newfile.txtthen type content, press Ctrl+D to save - Combine with pipes:
cat access.log | grep ERROR | wc -l
See Also
Related Commands
- less — View files with scrolling and search
- more — Simple file pager
- head — Show first N lines
- tail — Show last N lines
- tac — Reverse line order






