Let’s learn about the cat command in Linux with examples and options
Cat command is basically used for,
to view the content of the file,
can create a new file,
also, we can append the content of the file,
and put the content or append into another file.
How to VIEW the CONTENT of A SINGLE file.
Command: # cat first_file
So, while using the cat command we can check the content that our file contains and we have the file named “first_file”.
How to VIEW the CONTENT of A MULTIPLE files.
Command: # cat first_file second_file third_file
So, now we have to see the content of Multiple files for that we have a three file with the name “first_file, second_file, and third_file”.
How to VIEW the NUMBER of LINES by using cat command.
Command: # cat -n check_the_number_of_line
So, suppose we have to check the number of lines for the file, then we will use -n option with the cat command.
And we have the file named “check_the_number_of_line” and with that, we have used -n option to check the number of lines.
How to CREATE a NEW FILE using cat command in Linux.
Command: # cat > create_a_new_file
So, to create a new file by using cat command we will use > redirection sign.
After that put your content as you want and press control + d key from the keyboard to get out from the terminal
How to APPEND the CONTENT in a file.
So, now we have to append the content in an existing file let’s look out the example.
Command: # cat >> create_a_new_file
So, to append the content we have used >> sign with the cat command and then we can start writing our content
When the content part has been written just press control + d key to come out from the terminal.
How to APPEND a FILE CONTENT into ANOTHER FILE.
Now we have to add a whole content of a file into another file, we will use >> sign.
Command: # cat second_file >> third_file
So, we can see that there are two files second_file and the third_file, and we have put all the content of second_file into the third_file.
How to PUT the CONTENT into a NEW file.
In this example, we will copy our whole content into the new file by using a > sign.
Command: # cat create_a_new_file >> copy_the_content
So, now we can see the content in create_a_new_file and we have copied the whole content in copy_the_content file.
How to COPY THE CONTENT of MULTIPLE File a SINGLE File.
Suppose we have a multiple files and we have to copy into a single file, then we will use > sign
Command: # cat first_file second_file third_file > all_in_one_file
So, there are three files first_file, second_file, and third_file we have to copy all the content into a single file.
How we can CHECK the END of LINE.
Command: # cat -E check_the_number_of_line
Suppose we have to check whether the line has been ended or not, so we will -E option.
So, at the end of a line it will show a $ sign while using -E option.
How to SUPPRESS the EMPTY LINES by cat command in Linux.
Command: # cat -s suppress_file
So, what to do if we have more empty lines in a file and don’t want in our output.
So, we will -s option that will suppress the empty line of the file.
A cheat sheet for a cat command
So Guys lets ready for Quiz
Can we append the file by using a cat command?
Can we create a folder by using a cat command?
-n option is used for?
Can we view the multiple files using cat command?
Which command is used to append the file
Share your Results:
To learn about ls command refer this link.
Also, refer a Practice link.
Thanks to read the POST keep supporting us.