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:
1 | $ cat filename [press enter] |
Suppose we have two files Employee.txt and Data.txt as shown below:
1 2 3 4 5 | Name | Post | Salary | DOB | Age | Aditya | DGM | 100000 | 03-02-1987 | 30 | Kumar | GM | 700000 | 05-02-1977 | 41 | Manish | CA | 500000 | 10-02-1997 | 20 | Rajeev | CLERK| 300000 | 05-05-1987 | 31 | |
File 1: Employee.txt
File 2: Data.txt
Example: To see the content of file write command as follows.
1 2 3 4 5 | $ cat Data.txt Employee.txt [press enter] Hello, I am aditya From NIT Patna Asst. Prof. |
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.
1 2 3 4 5 6 7 8 9 10 | $ cat Data.txt [press enter] Hello, I am aditya From NIT Patna Asst. Prof. Name | Post | Salary | DOB | Age | Aditya | DGM | 100000 | 03-02-1987 | 30 | Kumar | GM | 700000 | 05-02-1977 | 41 | Manish | CA | 500000 | 10-02-1997 | 20 | Rajeev | CLERK | 300000 | 05-05-1987 | 31 | |
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.
1 2 3 4 | $ cat > myfile.txt [press enter] > Hello, I am aditya This is new file. [ctrl+d] [press ctrl+d to end of input] |
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.