Bootstrap FreeKB - Linux Commands - cat or tac (view the content of a file)
Linux Commands - cat or tac (view the content of a file)

Updated:   |  Linux Commands articles

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$

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


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