$linuxjunkies
>

cat(1)

Concatenate and print files to standard output.

UbuntuDebianFedoraArch

Synopsis

cat [OPTION]... [FILE]...

Description

Read one or more files and write their contents to standard output. If no files are specified, or if a file is named -, cat reads from standard input. Useful for viewing file contents, combining files, and piping data to other commands.

cat does not buffer its output, making it suitable for real-time streaming and interactive use.

Common options

FlagWhat it does
-nnumber all output lines
-bnumber non-blank output lines
-ssqueeze multiple adjacent blank lines into one
-Ashow all non-printing characters (tabs as ^I, line ends as $)
-Edisplay $ at the end of each line
-Tdisplay tab characters as ^I
-vshow non-printing characters using ^ and M- notation
-esame as -vE

Examples

Display the contents of a single file

cat file.txt

Display contents of multiple files in sequence

cat file1.txt file2.txt file3.txt

Concatenate multiple files and write output to a new file

cat file1.txt file2.txt > combined.txt

Display file with line numbers for all lines

cat -n file.txt

Display file with line numbers only on non-blank lines

cat -b file.txt

Show invisible characters like tabs and line endings

cat -A file.txt

Read from standard input and write to a file (Ctrl+D to end)

cat > newfile.txt

Mix stdin with file contents (read stdin, then file, then stdin again)

cat - file.txt -

Related commands