How to Use Unix Cat Command

In this tutorial we will show you how to use the unix cat command.
This command is used for displaying the contents of the file. The unix commands for cat can also be used for combining copies of the files and creating new ones.
To understand how to work with the cat command, follow the tutorial steps given below.


Step 1 – List the directory contents

Let’s look at an example over here. First, let’s list the contents of the directory here.

List the contents of the directory

Step 2 – Display contents of the text

Let’s display the contents of the text file over here. For that, simply write “cat text.txt” And over here, you can see all the data being displayed on the screen.

See contents of the text file

Step 3 – Display contents of two files together

Now we will see how we can combine two files with the cat command. Over here, notice that there are two text files. So, over here, we will type
“cat textfile textfile1”.
You will see that the contents of both the files will be displayed together.

Combine the display of two files together

Step 4 – Combine two text files

Now let’s use the unix cat command to create a new text file from the terminal.
For that type “cat > file1
You will be required to fill the content in the newly created file. So let’s write a single line over here and then press the CTRL + D key. This is used for saving the file.

Join two text files

Step 5 – Check if the files have been combined

Let’s check whether the changes had been saved or not. For that, simply write the cat command followed by the name of the file.
And over here, you can see that the changes had been made, and the file contains the content that we had entered earlier.
So that’s it, follow the steps above to learn how unix commands for cat can be used to list the contents of an existing file or even combining two such files.

Check if the text files data has been combined