Exploring cat - Linux Commands

  • #linux

What is the cat Command in Linux?

The cat command stands for concatenate. It is used to read, concatenate, and write the contents of files to the standard output (usually the terminal). It is one of the most commonly used commands in Linux for viewing file contents.

Basic syntax:

cat [option] [file]

Example:

cat file-name

Common cat Use Cases

Viewing a Single File

cat filename.txt

Concatenating Multiple Files

You can combine the contents of multiple files into a new file using the > operator.

cat file1.txt file2.txt > combined.txt

Appending to an Existing File

Use the >> operator to append text or file contents to the end of an existing file.

cat new-data.txt >> existing-data.txt

cat Command Options

OptionDescription
-A, --show-allEquivalent to -vET, showing non-printing characters (except for spaces and tabs), end of lines, and tabs
-b, --number-nonblankNumber all non-empty output lines
-E, --show-endsDisplay a dollar sign $ at the end of each line
-n, --numberNumber all output lines
-s, --squeeze-blankSuppress repeated empty output lines
-T, --show-tabsDisplay TAB characters as ^I
-v, --show-nonprintingUse ^ and M- notation, except for LFD and TAB characters

Additional Help

You can explore more by using the commands:

cat --help
# or
man cat

Thank you

Thank you for your time and for reading this!

Related Concepts