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

← All Linux commands · Linux cheat sheet