cat Linux Commands
What is Linux cat Command?
Explanation
cat COMMAND:cat linux command concatenates files and print it on the standard output.
SYNTAX :
cat [OPTIONS] [FILE]...
OPTIONS:
-A |
Show all. |
-b |
Omits line numbers for blank space in the output. |
-e |
A $ character will be printed at the end of each line prior to a new line. |
-E |
Displays a $ (dollar sign) at the end of each line. |
-n |
Line numbers for all the output lines. |
-s |
If the output has multiple empty lines it replaces it with one empty line. |
-T |
Displays the tab characters in the output. |
-v |
Non-printing characters (with the exception of tabs, new-lines and form-feeds) are printed visibly. |
EXAMPLE:
- To Create a new file:
cat>file1.txt
This command creates a new file file1.txt. After typing into the file press control+d (^d) simultaneously to end the file.
- To Append data into the file:
cat>>file1.txt
To append data into the same file use append operator >> to write into the file, else the file will be
overwritten (i.e., all of its contents will be erased).
- To display a file:
catfile1.txt
This command displays the data in the file.
- To concatenate several files and display:
catfile1.txtfile2.txt
The above cat command will concatenate the two files (file1.txt and file2.txt) and it will display the output in the screen.
Some times the output may not fit the monitor screen. In such situation you can print those files in a new file or
display the file using less command.
catfile1.txtfile2.txt|less
- To concatenate several files and to transfer the output to another file.
catfile1.txtfile2.txt>file3.txt
In the above example the output is redirected to new file file3.txt. The cat command will create new file file3.txt and store the concatenated output into file3.txt.