Skip to main content

Module 1: File & Directory Management

Lesson 11: cat Command

In this lesson, you'll learn how to use the cat command to display, create, and concatenate files in Linux.

The cat (short for "concatenate") command is one of the most frequently used commands in Linux that comes pre-installed in most Linux distribution systems and is primarily used to display the content of existing files.

Moreover, the cat command can be utilized by the user to concatenate multiple files, create new files, append content to existing files, view the content of a file, and redirect output in the terminal or files.

The cat command can also be used to format the output of the file with the help of different options, such as adding numbers before each line of the file's content.

Additionally, it can execute in combination with other commands to perform various tasks including providing page navigation and conversion of file format to binary or hexadecimal.

Let's now discuss the syntax of the cat command along with some examples to illustrate its usage.

cat Command Syntax

The cat command can accept multiple options and file name arguments as shown:

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

Let's understand the above syntax:

  • [OPTION] - Users can provide multiple options to alter the behavior of the command. The options start with a hyphen (-), such as -E is used to display line ends and -n to display numbers before lines.
  • [FILE] - The file argument specifies the file which will be manipulated by the command. However, users can provide names of multiple files separated by space.

cat Command Options

Option Description
-n Number all output lines
-E Display $ at the end of each line
-T Display tab characters as ^I
-s Suppress repeated empty output lines
-v Show non-printing characters
-b Number non-empty output lines only
-A Equivalent to -vET combined

Note: To read in detail about all the available options of the cat command, execute the cat --help command in your Linux terminal:

$ cat --help

Now, it's time to discuss examples of the cat command.

1. Display Contents of a File in Linux

The basic functionality of the cat command is to display the content of an existing file in Linux. For that purpose, provide the name of the file with no option, as shown.

$ cat Documents/tecmint1.txt
Welcome to TecMint
Linux Howtos and Tutorials

Here in the command, the content of the file "tecmint1.txt", which is located in the "Documents" directory will display.

2. Display Contents of Multiple Files in Linux

The cat command can also be utilized to show the contents of more than one file by providing the file names separated by space, as shown:

$ cat tecmint1.txt tecmint2.txt
Welcome to TecMint
Linux Howtos and Tutorials
TecMint is the best Linux resource website.

In the above output, we can see the contents of both files in the terminal. The first two lines are from the file "tecmint1.txt", whereas the last line of the output is the content of the "tecmint2.txt" file.

3. Create a File with cat Command

Pro TecMint Β· Root Plan
This Article is for Root Members
Join Root to read the full article and unlock everything

Full Access to Every Article, Course & Certification Track

Join thousands of Linux professionals who use Pro TecMint to advance their careers.

Ad-free access to all premium articles
All courses: Learn Linux, Bash, Golang, Ubuntu and more
RHCSA, RHCE, LFCS & LFCA certification prep
New courses added every month
Private Telegram community & priority support
Root Plan
$8/mo
or $59/year billed annually
Save $37 with annual plan
Start Reading This Article in the Next 60 Seconds
Join Root Plan β†’