Home » linux » Linux and Unix cat command tutorial with examples

Linux and Unix cat command tutorial with examples

cat command is used to see the content of the file.
cat command is also used to concatenate two or more file.
cat command is also used to create new files.

Syntax:

Suppose we have two files Employee.txt and Data.txt as shown below:

File 1: Employee.txt

File 2: Data.txt

Example: To see the content of file write command as follows.

Note: Above command display the content of file Data.txt.
Display more than one file at a time / or concatenate two or more file
“cat” command display more than one file at a time or concatenate more than two files. “cat” command display content of the second file immediately after the first file without any information.

Note: Above command concatenated both Data.txt, Employee.txt files. Or it displays the content of two files one after another immediately after the first file without any information.
Create a new file using cat command: To create a new file write cat command followed by “>” sign and then the name of the file.

When we enter command and press enter new file will be created (in above command new file is “myfile.txt will create ) and it will wait for input/ or write something on newly created file.
We have entered two lines it will write on myfile.txt.
When the write is over press “ctrl+d” to terminate cat command.

Managed by MochaHost - Fast & Easy WordPress Hosting