View the content of a file using the CAT or TAC command in Linux

Home > Search > Linux commands
  by

In it's simplest form, the CAT command can be used to view the contents of a file.

[root@server1 ]# cat file1
Hello     world

 

More than one file can be viewed.

[root@server1 ]# cat file1 file2
Hello     world
How    are     you     today?

 

With cat, we can read the content of one file as STDIN and redirect the content to another file as STDOUT. In another words, we overwrite file2 with the contents of file1.

[root@server1 ]# cat file1 > file2

 

Let's view each file.

[root@server1 ]# cat file1 file2
Hello     world
Hello     world

 

The -n and -b options number the lines.

[root@server1 ]# cat -n file1 file2
      1 Hello     world
      2 Hello     world

[root@server1 ]# cat -b file1 file2
      1 Hello     world
      2 Hello     world

 

Let's say there is a tab between the words Hello and world in file1 and file2. The -vET option can be used to view the metadata of the tabs and the end of each line. ^I is a tab, and $ is the end of a line.

[root@server1 ]# cat -vET file1 file2
Hello^Iworld$
Hello^Iworld$

 

The -A option does the same thing as -vET.

[root@server1 ]# cat -A file1 file2
Hello^Iworld$
Hello^Iworld$

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments