Categories: Ubuntu

Use of Cat Command in Linux

Cat command used frequently in Linux/Unix similar like Operating Systems. Cat command is used to create files. Whenever you create a new file through Cat command you need to put redirection operator “>” between Cat command and name of your file

Cat Syntax

cat [OPTION] [FILE]

View a file Content

While using following command it will display content of /etc/selinux/config file

cat /etc/selinux/config
Use of cat command in linux 8

View multiple file content

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

cat newfile1 newfile2 newfile3

and it’s gonna list content of all three files respectivily.

Create a File with Cat Command

cat > test1
Use of cat command in linux 9

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

Now you gonna see the added text in a test file using following command.

cat test1
Use of cat command in linux 10

Note: If you already have an existing file then you add text in it while using Redirection Opertor “>” it’s gonna overwrite previous content with new one in doing so, you gonna lose your old data. Check following command for a referance.

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

Now we gonna add more text in a test file.

cat > test1
Use of cat command in linux 11

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

Now check “test” file again and you will see that previous text has removed and new text taken its place.

cat test1
Use of cat command in linux 12

Append text in a file

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

cat >> test1
Use of cat command in linux 13

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

cat test1
Use of cat command in linux 14

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 test1 test2 > test3

That’s about it, you get an idea how to use cat command in many ways. See manual using command “man cat” for more information.

The post Use of Cat Command in Linux appeared first on Osgrove.

Ubuntu Server Admin

Recent Posts

Advantech AOM-2721 is now Ubuntu Certified

Canonical announces that the Advantech AOM-2721 is officially joining the list of Ubuntu Certified Hardware.…

1 hour ago

Ruby and Rails Performance Roundup: The Backlog Edition

Yet again instead of tweets, a blog post. The backlog got out of hand -…

1 hour ago

How to Deploy OpenProject on Ubuntu VPS

This article provides a guide demonstrating how to deploy OpenProject on Ubuntu VPS. What is…

2 hours ago

Canonical integrates NVIDIA Nemotron 3.5 Lightning with Ubuntu for always-on AI agents

Canonical is pleased to announce that  NVIDIA’s newly introduced NVIDIA Nemotron 3.5 Lightning, an open,…

2 days ago

Xfwl4’s Second Preview Release

I’m pleased to announce the second preview release of xfwl4, Xfce’s Wayland compositor, version 4.21.1.…

2 days ago

How to Install, Secure, and Set Up MySQL on Ubuntu 26.04 LTS

If you have been using an ecommerce store to place online orders or have been…

3 days ago