Gice

Technology and General Blog

Linux command cat limited for ‘concatenate’, is a quite useful command.  Using the cat command, you can build a file, watch file material, concatenate data files, and file output redirection. We will talk about the distinctive uses of the cat command with some examples in this write-up.

Basic Syntax of Cat command

The subsequent syntax is employed for the cat command:

$ cat [options] [file-name]

File-title is the title of a file.

Use the next command to explore all cat selections:

Print file information by the cat command

Using the cat command, you can display the file articles on the terminal as follows:

For example, to check out the content material of the ‘test_file.txt’ file, kind the under-pointed out command on the terminal:

The content of the over file will be shown on the terminal.

In the same way, to show the content material of multiple data files, use the following command:

$ cat exam_file.txt check_file1.txt

The earlier mentioned command will demonstrate you the information of the exam_file.txt and exam_file1.txt on the terminal.

File creation making use of the cat command

You can use the cat command to develop a new file.

For instance, we are generating a file with the identify ‘new_filetest.txt’ by executing the adhering to command:

Now, the user will input material into this file and then ‘Ctrl+d’ to depart this file. The written content is composed in ‘new_filetest.txt’ that you can screen by way of the cat command.

Use of more and fewer choices with cat command

If a file has a substantial written content and you need to have to scroll to perspective extra file content. In this circumstance, use the adhering to choices with the cat command:

$ cat testfile.txt | extra

$ cat testfile.txt | less

Print line quantity with file written content

Use the cat command alongside with possibility ‘-n’ to exhibit the line variety of file written content as follows:

Screen tab-separated figures

Use the option ‘-T’ and the cat command to show the tab-divided characters in a line.

In a line, the tab room will be filled with ‘^I’ character, which is also revealed in the following screenshot:

Print ‘$’ at the Close of Strains

To show the ‘$’ at the conclusion of traces, use choice ‘-e’ with cat command as follows:

The over choice is helpful when you want to shrink the several traces in a solitary line.

Redirect file written content

By way of the cat command, the consumer can redirect the common output into a new file.

For instance, to duplicate 1 file’s articles into a different file, you can use the cat command. We have a file with the name check_file.txt, and the other is take a look at_file1.txt.  So, to duplicate the content of ‘test_file.txt’ to a ‘test_file1.txt’, use the cat command with ‘>’ operator as follows:

$ cat test_file.txt > new_file.txt

If ‘test_file1.txt’ does not exist then, it will build a file with this identify.

To append the written content of ‘test_file.txt’ to a ‘test_file1.txt’, use the operator ‘>>’ in the cat command as follows:

$ cat take a look at_file.txt >> take a look at_file1.txt

Overlook the repeated empty traces

Working with the cat command along with option ‘-s’, you can omit the vacant lines from the output.

File concatenation making use of the cat command

The cat command is used to concatenate the file articles. For example, the concatenate the written content of exam_file.txt and exam_file1.txt and then compose information into a new file mergefile.txt by using the ‘>’ operator as follows:

$ cat take a look at_file.txt exam_file1.txt > mergefile.txt

Summary

We have described the Linux cat command with examples in this write-up. We have how the cat command can help a Linux user when he/she is doing work on a technique. From the higher than illustrations, I hope you have learned a ton. Make sure you give your feedback by way of reviews.

Leave a Reply

Your email address will not be published. Required fields are marked *