cat(1)
Concatenate and print files to standard output.
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
| Flag | What it does |
|---|---|
-n | number all output lines |
-b | number non-blank output lines |
-s | squeeze multiple adjacent blank lines into one |
-A | show all non-printing characters (tabs as ^I, line ends as $) |
-E | display $ at the end of each line |
-T | display tab characters as ^I |
-v | show non-printing characters using ^ and M- notation |
-e | same as -vE |
Examples
Display the contents of a single file
cat file.txtDisplay contents of multiple files in sequence
cat file1.txt file2.txt file3.txtConcatenate multiple files and write output to a new file
cat file1.txt file2.txt > combined.txtDisplay file with line numbers for all lines
cat -n file.txtDisplay file with line numbers only on non-blank lines
cat -b file.txtShow invisible characters like tabs and line endings
cat -A file.txtRead from standard input and write to a file (Ctrl+D to end)
cat > newfile.txtMix stdin with file contents (read stdin, then file, then stdin again)
cat - file.txt -