Cat command: view file, create file, append file, concatenate file

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

OR

cat < filename

Now, to open ok.txt, I will go in terminal and type:
cat command to display text filesAs you can see the content of the file ok.txt is displayed in the terminal.

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.

I am going create a file hello and write something in it and later display the content of hello file.
create 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

append text file using cat command

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:

concatenate exampleThe syntax to concatenate is:

cat filename filename

concatenate using cat commandYou can find more information about cat command in the manual page of cat command.

To view the manual page of cat command type:

man cat
0saves
Posted in Linux, Linux Command | Tagged , , , , , , , , , | 1 Comment

One Response to Cat command: view file, create file, append file, concatenate file

  1. Gary UNITED KINGDOM Google Chrome Ubuntu Linux says:

    As a novice I found this tutorial easy to understand. Excellent.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>