Notice: Undefined index: HTTP_ACCEPT in /home2/hostsall/public_html/wp-content/plugins/wp-enable-webp/wp-enable-webp.php on line 26
class="post-template-default single single-post postid-4823 single-format-standard wp-custom-logo wp-embed-responsive oxygen-body no-webp-support elementor-default elementor-kit-2037 elementor-page-5457" >

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

Read More »
HostSall © Copyrights 2020. All Rights Reserved.
WeCreativez WhatsApp Support
Our customer support team is here to answer your questions. Ask us anything!
👋 Hi, how can I help?