Back to the command reference

cat

FilesBeginner In simulator In real Linux

Print or concatenate files

Name: cat = concatenate

You can practise it right away in the simulator, and use it in real Linux mode too.

Description

cat reads each file in turn and writes the contents, joined together, to standard output; with no files it reads standard input. Its purpose is to concatenate files, though it is mostly used to show short ones.

For long files less is more comfortable; for just the beginning or end use head or tail.

Syntax

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

Common options

-n / --numberNumber all output lines
-b / --number-nonblankNumber only lines that are not empty
-s / --squeeze-blankShow runs of empty lines as one
-A / --show-allShow tabs, line ends and other invisible characters
-E / --show-endsShow $ at the end of each line (to see trailing spaces)
-T / --show-tabsShow tabs as ^I

Examples

  • $ cat README.md

    Show a file

    Explain
  • $ cat -n documents/todo.md

    Show a file with line numbers

    Explain
  • $ cat documents/notes.txt documents/todo.md > all.txt

    Join two files into one

    Explain

Related