Linux Cat Command
Cat or “concatenate files and print on the standard output” is a Linux command to print file content on the standard output like screen. This is one of most popular Linux commands. I think that every Linux administrator has executed the below command at least one time 😉 :
# cat /var/log/messages
So this is actually very useful and popular command.
Usage and Examples
Cat command has few options but has lot of usages.
Show file content: If Cat command run without options, it will shows you the content of the file or files.
Show multiple files content: You can view content of multiple files by entering more than one file name in command line, see the below example:
Create New File: You be able to create new file by Cat command. Run the below command and then enter some strings and when it’s finished hit Enter, if you are end of a line and then Ctrl+D for save the new file. Please consider that existing files will be overwrite by run same command.
Join Multiple Files: Joining multiple files to a file is possible by Cat command. Here is an example:
# cat file1.txt file2.txt file3.txt > all-files.txt
Show Line Number: Cat command can show line number and content together. This is useful when you are reading files for debugging:
# cat -n sample1.txt
1 This is frist line.
2 This is second line
3 This is third line.
4 This is fourth line.
5 This is fifth line.
Read more about “cat” at its man page.
5,563 total views, 104 views today