29 January 2021
1 min read

Cat Command in Linux [Display, Concatenate, Create]

1. Introduction

The cat command, short for concatenate, is one of the most commonly used commands in Linux. It is primarily used to concatenate and display the contents of files. It can also be used to create, modify, or combine files.

The cat command is normally used to view short files or combine files. Basically, it can provide a quick display of the entire file.

When comes to interactive navigation or searching within the file or large file, cat command is not recommended. As its dumps entire file content to the screen at once – not convenient if you want to read through it.

2. Syntax and Options

The cat command takes the following command syntax:

cat options [filename] ...

The following table shows common options for cat:

OptionsDescription
-b or –number-nonblankNumber the non-blank output lines, starting at 1.
-E or –show-endsDisplay a dollar sign $ at the end of each line before the newline.
-v or –show-nonprintingDisplay non-printing characters in caret notation (^) and M- notation, except for the LFD (Line Feed) and TAB characters
-eEquivalent to -vE
-T or –show-tabsDisplay TAB characters as ^I
-A or –show-allEquivalent to -vET
-n or –number   Numbers all output lines starting at 1.
-s or –squeeze-blank Replace multiple adjacent empty lines with a single empty line in the output
–helpDisplay help message
–versionPrints version information and exit

3. Displaying File Contents

To display the content of a file type the cat command followed by the name of file(s).

cat myfile1.txt

This command outputs the content of the file named myfile1.txt to the terminal.

For large files, the only option to navigate the file content is to scroll up using the mouse.

If you wish to view the contents of multiple text files at a go, simply specify the files in one line separated by a space. In this example, we have displayed the contents of two files, one after the other.

cat myfile1.txt myfile2.txt

4. Create a new file 

Cat command allows you to create a file and quickly add content to it.

Bobbin Zachariah

Bobbin Zachariah

Bobbin Zachariah is the editor-in-chief of Linoxide and has an experienced team of Linux enthusiastic authors who makes this blog awesome. Linoxide is one of the top 20 Linux Blog by whizlabs.

Leave a Reply

Your email address will not be published.

Previous Story

Linspeed – Gui Tool to Test Internet Speed on Linux Desktop

Next Story

Ubuntu Change Hostname + Make it Permanent

Latest from Blog

Top 8 Reasons to Use Garuda Linux

Have you been going back and forth between multiple Linux flavors in search of an exciting experience? Or perhaps you are coming from a Windows or MAC environment and want to try

How to Rename Multiple Files in Linux

In a Linux system, you can easily rename a file using mv command. But, if you have multiple files which you want to rename, in this situation you need some extra tools

How to Install TensorFlow on Ubuntu 20.04

Tensorflow is an open-source platform for machine learning and artificial intelligence. It is developed by the Google Brain team. It contains tools, libraries, and community resources for developers to build ML powered
Go toTop