text
cat
Concatenates files and prints them to standard output. Also useful as a simple viewer or to feed content into pipelines.
cat [OPTION]... [FILE]... Common flags
| Flag | Purpose |
|---|---|
| -n | Number every output line |
| -b | Number non-empty output lines |
| -s | Squeeze consecutive blank lines to one |
| -A | Show all non-printing characters (equivalent to -vET) |
| -E | Display $ at end of each line |
| -T | Display TAB as ^I |
Examples
cat /etc/hostname Print a file's contents
cat a.txt b.txt > combined.txt Concatenate two files into one
cat -n script.sh View a script with line numbers
cat -A weird.txt Reveal tabs, non-printables, and line endings
Gotcha
Avoid useless cat like 'cat file | grep foo' -- just run 'grep foo file' to skip the extra process.
Related commands
head
Outputs the first part of files. Defaults to the first ten lines but can trim by any line or byte count.
tail
Prints the last part of files. Essential for log inspection, especially with the follow flag to stream new lines.
grep
Searches text for lines matching a regular expression. Central to log analysis and pipeline filtering.
sed
Stream editor that applies a small program to each line of input. Widely used for search-and-replace and inline file edits.
awk
Pattern-action language for processing columnar text. Excellent for reshaping tabular data, aggregating fields, and quick reports.