cat Command

The cat command is one of the most frequently used commands in Linux. It reads files sequentially and displays their content on the terminal.

Syntax

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

Description

The cat command concatenate files and print on the standard output. When no file is specified, or when file is -, it reads from standard input.

Common uses include:

  • Display file contents
  • Concatenate multiple files
  • Create new files
  • Copy file contents

Common Options

Option Description
-n Number all output lines
-b Number non-blank output lines
-s Suppress repeated empty output lines
-T Display TAB characters as ^I
-E Display $ at end of each line
-A Equivalent to -vET (show all)

Examples

Display file contents

cat filename.txt

Displays the contents of filename.txt

Display multiple files

cat file1.txt file2.txt

Displays contents of file1.txt followed by file2.txt

Display with line numbers

cat -n filename.txt

Shows file contents with line numbers

Create a new file

cat > newfile.txt
Type your content here
Press Ctrl+D to save

Creates a new file and allows you to enter content

Concatenate files

cat file1.txt file2.txt > combined.txt

Combines file1.txt and file2.txt into combined.txt

Append to a file

cat >> existing_file.txt
Additional content
Press Ctrl+D to save

Appends new content to an existing file

See also