The cat command

The cat command allows us to create single or multiple files, to view the content of a file or to concatenate files and redirect the output to the terminal or files.

The "cat" stands for 'concatenate.' and it's one of the most frequently used commands in the Linux terminal.

Examples of uses:

  • To display the content of a file in terminal:

[root@academy tmp]# cat myfile.txt
hello world from Yaser Rahmati

[root@academy tmp]#
  • To display the content of multiple files in terminal:

[root@academy tmp]# cat file1.txt file2.txt
content inside file1.txt
content inside file2.txt
[root@academy tmp]#
  • To display all files in current directory with the same filetype:

[root@academy tmp]# ls
apa.txt  file1.txt  file3.txt         myfile.txt  myfolder2  yum.log
F1       file2.txt  ks-script-ggLlAt  myfolder    myfolder3
[root@academy tmp]# cat *.txt
content inside file1.txt
content inside file2.txt
hello world from Yaser Rahmati

[root@academy tmp]#
  • To display the content of all the files in current directory:

  • To put the output of a given file into another file:

  • Append the contents of file1 to file2:

  • To concatenate two files together in a new file:

  • Some implementations of cat, with option -n, it's possible to show line numbers:

Last updated