Skip to main content

cat (Concatenate)

Explanation

The cat command is one of the most frequently used commands in Linux. It reads files sequentially, writing them to standard output. It's commonly used to view the contents of short files, combine multiple files into one, or create new files.

Basic Syntax

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

Common Flags and Options

FlagDescription
-n, --numberNumber all output lines.
-b, --number-nonblankNumber nonempty output lines, overrides -n.
-E, --show-endsDisplay $ at end of each line.
-T, --show-tabsDisplay TAB characters as ^I.

Real-world Examples

  1. View the contents of a file:

    cat file.txt
  2. Concatenate two files into a new file:

    cat file1.txt file2.txt > newfile.txt
  3. Append the contents of one file to another:

    cat new_data.txt >> existing_file.txt