cat command allows us to create single or multiple files, view contain of file, concatenate files and redirect output in terminal or files.

Syntax of cat command

$ cat [option] [files]



1. For creating files 


$ cat > file.txt


abhisharmaofficial.blogspot,com


2. View the content of files


$ cat linux.txt

this command show the content of file linux.


abhisharmaofficial.blogspot.com


3. View the content of more than two files 

$ cat linux.txt aman.txt

this command show the content of files linux and aman simultaneously.


abhisharmaofficial.blogspot.com


4. Showing the line numbers

$ cat -b aman.txt

this command show the line number of the every content line of the file having non blank line. This command option skip the blank line of the file if have.


abhisharmaofficial.blogspot.com


$ cat -n aman.txt


this command added the line number of the every content line of the file having non blank line as well as blank line. This command option skip the blank line of the file if have.


abhisharmaofficial.blogspot.com


5. move the content of one file to another file.

$ cat aman.txt >> linux.txt

This command add the all content of file aman.txt into the end of the file linux.txt.

The content of the both files will be saved no one be over witted. 


File 1 : aman.txt



File 2 : linux.txt





When you run the command the content of aman.txt moves into the linux.txt

The files look like that


abhisharmaofficial.blogspot.com

6. over- write the content of files. 

$ cat aman.txt > linux.txt

This command over - write the content of file linux.txt by the content of file aman.txt.

abhisharmaofficial.blogspot.com

abhisharmaofficial.blogspot.com


Mean the content of linux file will be removed and new content of the file aman.txt will be added at the last of linux.txt.

abhisharmaofficial.blogspot.com

7. Move the content of two or more files into a Single file. 

$ cat test1.txt test2.txt > result.txt

This command will create a new file result.txt and the content of files test1.txt and test2.txt will moved into the new file result.txt.

abhisharmaofficial.blogspot.com

abhisharmaofficial.blogspot.com


abhisharmaofficial.blogspot.com



Your feedback is very important for us :)