Basic Cat Command Examples in Linux

The cat command is very frequently used in Linux operating system. Cat command is used to view the content of the file, create one or multiple files and concatenate the file.

In this article, we are going to do practice on cat command in Linux with some examples.

Basic/General syntax of cat command

cat {...option} {...file-name}
cat /etc/shadow

To view the content of a file via cat command

cat /etc/devopscheetah.txt


output:-
welcome to DevopsCheetah.com

To view the content of multiple files via cat command

cat file1  file2


output:-
Hello India
Hello World

To view contents of a file preceding with line numbers.

cat -n file1

output:-
1. Hello India

Create a file with the cat command.

cat > abc.txt

Save the output to the file via cat command, but we need to notice two things here > (single greater than symbol) will overwrite the data so be careful when you running this command and >> (double greater than symbol) the content will append at the end of the file.

cat file1 > file3

cat file3


output:-
Hello India



cat file2 >> file3

cat file3


output:-
Hello India
Hello World

Through this article, we learned some basics of cat command.

Leave a Reply

Your email address will not be published. Required fields are marked *