Linux Commands | File Management | cat Print File Contents

cat Command

The cat command prints file contents.

It can also be used with input/output redirection (>, >>) to create files or write content to files.

cat is short for “catch”.

Syntax

cat [options] [file name]

cat Command Examples

Example 1

Print the contents of /etc/passwd.

cat /etc/passwd

Example 2

Print the contents of /etc/passwd with line numbers on the left.

cat -n /etc/passwd

Note: # indicates a comment.

Example 3

cat > [file name]
  [enter file contents] (press Ctrl+D to finish input)

If the file exists, its contents are overwritten. If it does not exist, it is created and the entered content is written.

Example 4

cat >> [file name]
  [enter content to append]

If the file exists, the content is appended. If it does not exist, it is created and the entered content is written.

Note

  • > (write): creates a file or overwrites it.
  • >> (append): creates a file or appends content.