The cat command is one of the most frequently used command in Linux/Unix like operating systems. cat command allows us to create single or multiple files, view contain of file, concatenate files and redirect output in terminal or files. In this article, we are going to find out handy use of cat commands with their examples in Linux.
Display Contents of File
By using below command to show the contents of the file passwd
View Contents of Multiple Files in terminal
By using below command to show the contents of the multiple files eg.test1 and test2
Create a File with Cat Command
By using below command to create a file cat3
Use Cat Command with More & Less Options
By using the command to show the file details with more and less option
Display Line Numbers in File
With -n option you could see the line numbers of a file song.txt in the output terminal
Display Multiple Files at Once
By using below command,Display multiple files at once
Use Standard Output with Redirection Operator
We can redirect standard output of a file into a new file else existing file with ‘>‘ (greater than) symbol. Careful, existing contents of test1 will be overwritten by contents of test file.
Redirecting Multiple Files Contain in a Single File
Create a file called test4 and all output will be redirected in a newly created file by using below command
Sorting Contents of Multiple Files in a Single File
This will create a file test5 and output of cat command is piped to sort and result will be redirected in a newly created file.
This article shows the basic commands that may help you to explore cat command. You may refer man page of cat command if you want to know more options.