How to use cat command in Linux

Windows Articles

How to install NetBeans on Windows 10

Hi! Today we're going to talk a little about Netbeans. This is an integrated development environment that allows programming in various languages....

How to install Atom Text Editor on Ubuntu 20.04?

It is often said that the process of software development is complex. And this is true, therefore it is required to use...

How to install Brackets in Windows 10 plus extensions

Hello! Brackets is an open-source code editor designed by Adobe for web developers. Additionally, it has a very simple and modern interface...

How to install Docker on OpenSUSE 15.2 / 15.1?

Docker is a fairly popular technology in today’s sysadmin. It is logical to think because it means a complete change in the...

How to analyze the network with IP Tools for Android

Hi! If you want to analyze and adjust the network almost professionally, then this post is for you. Indeed, IP Tools is...
Muhammad Nabeel
Muhammad Nabeel
Network and System Administrator

cat (concatenate) is a standard Unix utility that reads files sequentially, writing them to standard output. The name is derived from its function to concatenate files. Cat is very popular command which is used in every Linux Operating System. In this article, we will use different cat example which may helpful for you.

Cat Syntax

cat [OPTION] [FILE]

View a file Content

So using below command I will show content of /etc/selinux/config file

cat  /etc/selinux/config

View multiple file content

If you want to see multiple files content, simply use following command.

cat file1 file2 file3 

In result you will see all three files content respectively on screen.

Create a File with Cat Command

cat > test

After that, you can type your desired text into the file and press CTRL+d to exit from file. sign “>” used to add text.

Now you can see the added text into test file using below command.

cat test

Note: if you have an existing file and add text in it using “>” sign, it will overwrite previous content with new, it mean you will lose your data. for clearly below is an example.

In above scenario we have created a test file and add text in it.

Now add more text in test file.

cat > test

After adding text, press CTRL+d to make changes and exit.

Now again see “test” file and you will see that previous text is removed and new is placed in in.

cat test

Append text in a file

Now if you want to add text in a file without losing existing content use “>>” signs in command.

cat >> test

Now see its content and you will see data is appended instead of overwritten.

cat test

Copy multiple files content in a single file.

If you want to copy multiple files data in a single file, simply use following command

cat test test1 > test2

That’s it, you have learned that how to use cat command in various ways. See manual using command “man cat” for more information.

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How to install NetBeans on Windows 10

Hi! Today we're going to talk a little about Netbeans. This is an integrated development environment that allows programming in various languages....

How to install Atom Text Editor on Ubuntu 20.04?

It is often said that the process of software development is complex. And this is true, therefore it is required to use...

How to install Brackets in Windows 10 plus extensions

Hello! Brackets is an open-source code editor designed by Adobe for web developers. Additionally, it has a very simple and modern interface...

How to install Docker on OpenSUSE 15.2 / 15.1?

Docker is a fairly popular technology in today’s sysadmin. It is logical to think because it means a complete change in the...

How to analyze the network with IP Tools for Android

Hi! If you want to analyze and adjust the network almost professionally, then this post is for you. Indeed, IP Tools is...