Cat command in Linux is very useful when we are working with the files. The file can be created, displayed, append using the cat command. Cat command also can be used to concatenate two files and display the output. First let us start with opening the files using cat command.
1) How to open text files in Linux using cat command?
I have a file called ok.txt in my home directory. The syntax for opening the text files using cat command is:
cat < filename
2) How to create files using cat command?
The syntax to create a file and write something in it is:
cat > filename
After you create the file, write anything in there. After you are done writing Press Ctrl+D to save and exit. You can see the content of file using cat command.
3) How to append in a text file?
I want to add something in hello file which I created earlier. To append the syntax is:
cat >> filename
4) How to concatenate and display content of all files:
I want to concatenate the files: hello and poker using cat command. The content of hello is the above picture and the content of poker is:
cat filename filename
To view the manual page of cat command type: