Cat Command in Linux (With Example and Screenshots)

Cat Command in Linux (With Example and Screenshots)

Hello friends, welcome to inet70. Today’s most important topic is about how to use the cat command in Linux operating system to read any file without opening it. The cat command is basically available for Linux and Unix operating systems. If you are a new Linux user, then you can read this article completely and start using it on your system.

Table of Contents

The “cat” command is used to read data from a file and give you the output of the content in the terminal. I have been using this tool from 2 years and I like it for its versatility. This tool can do anything with a document file. You can customize any text document easily. This tool has more uses like opening multiple text files on terminal, creating files and content, copying content of one file to other files, removing empty lines from the file, and displaying “$” sign on every line of content.

Now we can start getting more information about all shortcuts with examples and screenshots.

Cat Command in Linux

Here, I can provide all useful information, examples and screenshots. You can try this on your system. You can open any text document file in the terminal with the following command:

				
					cat [file_name]
				

Suppose I have one file “inet70.txt” available, and now I need to open this file with the cat command in Linux. Then you can follow the given command in the terminal:


cat inet70.txt

use the cat command

After following the command, you can show the output value in the terminal from the given screenshot. The content data is shown in the terminal. Now we can use this data for the normal file. Now we can test the more process from different conditions and apply changes.

Open multiple files with “cat”:

“cat” is able to open multiple files with a single command in the terminal. Suppose I have two files “file1” and “file2”. Now we can open both files with the “cat” command. Then follow the given command:


cat file1 file2

open multiple files with cat

From the given command, you can show the both files’ data in the terminal. It is the most powerful and useful feature of the cat command in Linux.

Create file and create content with “cat”:

This feature is an alternative to nano editor. You can create any file with the command in “cat”. You can put the following command to start making the files:

				
					cat >[file_name]
				

Here at [file-name] option, you can put the value of the file name and hit the enter key to redirect to the next step. For example, I can create one “testfile” with “cat”. Then I need to put the following command in the terminal:


cat >testfile

creade file with cat

After putting the enter key, the file creation process was started. You can start writing the content that you can store in the given file. In the last, put the ctrl-x save and ctrl-c to exit from the given file. Your file is successfully created.

Move the content of one file to another file with “cat”:

It is the most useful tool for sharing any file data from one file to another file. This works too fast and easily works without copying and pasting the content. From the given files, you can put the following command to write more content:

				
					cat [source_file]>[destination_file]
				

At the [source_file], you can put the file name when you copy the data from this file and move to the second file means [destination_file]. Now we can show this with an example.

Suppose I have two files “file1” and “file2”, and I need to move the data from “file1” to “file2”. Then I need to put the given command in the terminal:


cat file1>file2

move file data with cat

From the given screenshot, you can completely understand about moving the file data from one file to the second file.

Remove the empty lines from the line in “cat”:

This command is used to show all data from the terminal without counting any blank line. This also counts lines when you put any value. You can put the following command to display the number of total files lines properly:

				
					cat -b [file_name]
				

Now we can get more information with an example. Suppose I have one file available, and I need to display all data from the file and count the total number of lines. Then I need to put the following command:


cat -b file

remove empty line from content

From the given screenshot, you can show all available data from the file and display the number of lines.

Display “$” sign in every line in “cat”:

You can use the following command to show the display “$” sign on every line to understand where your line content is end. You can put the following command:

				
					cat -e [file_name]
				

Now we can start getting more information with an example. Suppose I have one file available. Now I can put the following command in the terminal:


cat -e file

show

You can show the output value on the terminal with “$” sign.

Thanks for visiting our site. If you like this content, subscribe to my blog by pressing the bell icon to get all new blog post notifications.