GARY IS COMING FOR YOU

You shouldn't have done that.

cat Tool Reference


cat (concatenate) displays file contents to stdout. One of the most fundamental Unix commands for reading files, combining files, and creating files.


Basic Usage

  • cat file.txt - Display file contents
  • cat file1.txt file2.txt - Concatenate multiple files
  • cat file.txt | less - Pipe to pager
  • cat > newfile.txt - Create file (Ctrl+D to finish)
  • cat >> file.txt - Append to file

Options

  • -n - Number all output lines
  • -b - Number non-blank lines
  • -s - Squeeze blank lines
  • -E - Show end of line with $
  • -T - Show tabs as ^I
  • -v - Show non-printing characters
  • -A - Equivalent to -vET

Common Examples

Display File

cat file.txt

Show file contents.

Number Lines

cat -n file.txt

Display with line numbers.

Create File

cat > newfile.txt
(type content)
Ctrl+D

Create new file from stdin.

Append to File

cat >> file.txt
(type content)
Ctrl+D

Append content to file.

Concatenate Files

cat file1.txt file2.txt > combined.txt

Combine multiple files.

Show Non-Printing

cat -A file.txt

Show all characters including tabs and line endings.

Pipe to Other Commands

cat file.txt | grep pattern

Use cat in pipelines.


Tips

  • Use -n to number lines for reference
  • Use -A to debug file formatting issues
  • Use > to create, >> to append
  • Essential for file inspection
  • Works great in pipelines
  • Use less or more for large files
  • One of the most basic Unix commands
  • Perfect for quick file viewing