What are Cat Commands in Linux?

If you have ever used Linux, then you are probably already familiar with cat commands in Linux. Cat commands are pretty useful, and they are very popular and versatile command in the Linux ecosystem. And are used very often.

There are four common usages of the cat command that you would get to see in a Linux ecosystem. You can use it for displaying a file, combining multiple files, echo text, or you can use it to create a new file.

But not all of us are well aware of different cat commands in Linux. If the same goes for you, too, then We are here to help you out.

We will be listing out some of the common cat commands in Linux that you can use. So here we go:




Basic Cat Commands In Linux

1. To view a single file

If you want to view a single file using the cat command, then you will need to use the below command in the terminal:

Command:

$cat filename

Output

It will show the content of the chosen file.

2. To view multiple files

To view multiple files at once in the terminal, you can run the following cat command:

Command:

$cat file1 file2

Output

This will show the content of file1 and file2.

3. To view the contents of a file preceding with line numbers

You can also use cat commands in Linux to view contents for a file preceding with line numbers. For this, you have to use the following command:

Command:

$cat -n filename

Output

It will show content with line number

example:-cat-n commands.txt

1)This is geeks

2)A unique array

4. Create a file

As mentioned earlier, you can use cat commands to create a file in Linux. For this, you have to use this simple command in the terminal:

Command:

$ cat >newfile

Output

It will create a new file named newfile.




5. Copy the contents of one file to another file

You can also use cat commands to copy the contents of one file to another file. For this, run the below command:

Command:

$cat [filename-whose-contents-is-to-be-copied] > [destination-filename]

Output

The content will be copied in the destination file.

6. Cat command can suppress repeated empty lines in output

With the help of cat commands in Linux, you can easily suppress repeated empty lines in Output. For this, run the below command:

Command:

$cat -s geeks.txt

Output

It will suppress repeated empty lines in Output.

cat commands in linux

7. Cat command can append the contents of one file to the end of another file

Cat commands are also helpful when it comes to appending the contents of one file to the end of another file.

Command:

$cat file1 >> file2

Output

Will append the contents of one file to the end of another file.

8. Cat command can display content in reverse order using tac command

You can also display content in reverse using the tac command. For this, run the below command: 

Command:

$tac filename

Output

Will display content in reverse order




9. Cat command can highlight the end of line

If you wish to highlight the last line of your file, you can easily do so by using a simple CAT command. For this, run the below command:

Command:

$cat -E "filename"

Output

Will highlight the end of line.

10. Instead of writing -vET in the command run -A command-line option

If you wish to run the –v, -E and the –T option together, then you can ditch writing the –vET command completely. Instead, you can simply run the –A command. For example:

Command

$cat -A "filename"

Final Words:

So those were some of the basic cat commands in Linux that you should be aware of. Now it is your call to go ahead and check these commands out and see how they are working for you. Also, for any other questions, do comment below.

cat commands in linux

Cat Commands in Linux

What are Cat Commands in Linux? If you have ever used Linux, then you are probably already familiar with cat commands in Linux. Cat commands are pretty useful, and they are very popular and versatile command in the Linux ecosystem. And are used very often. There are four common usages of the cat command that

Read More »
how to redirect http to https using htaccess

Redirect HTTP to HTTPS using htaccess

Wondering How to Redirect HTTP to HTTPS using htaccess? If your answer is yes, then read on. There is no doubt that an SSL certificate is an extremely important element on your website. If your website does not have a valid SSL certificate, then browsers like Google Chrome, FireFox and other Chromium based browsers will

Read More »
java for ubuntu

How to Install Java for Ubuntu

Do note that the following method should work on all Ubuntu Desktops, as well as on Ubuntu-based distros like Linux Mint. There are multiple versions and types of Java one can install on his/her computer which can confuse beginners sometimes. However, if you are not sure which Java version you have to install, you can

Read More »
how to make a bootable pen drive

How to make Pen Drive Bootable

Having a bootable Pendrive is always recommended especially if you are dealing with fixing computers or switching between different OS or experimenting on something. But for beginners, making a bootable pen drive is one of the difficult task as it seems complex and probably doesn't work every time since that are a couple of things

Read More »
dual boot ubuntu with windows 10

Dual boot Ubuntu and Windows 10

A lot of people keep thinking of different ways in order to run Windows alongside of their Linux distro like ubuntu. And it makes sense since a lot of people simply cannot afford to have two different machines for two different purposes. And while Linux is the king, many Games and professional software like Adobe

Read More »
install chrome on ubuntu

How to Install Chrome on Ubuntu

There are two ways to install Google Chrome on Ubuntu or any Linux distribution built on top of Ubuntu. In this article, we will guide to install Google Chrome on ubuntu using both the ways which is via terminal and the GUI itself. Don't worry if you don't understand these terms. Google Chome is one

Read More »
HostSall © Copyrights 2020. All Rights Reserved.