cat命令

cat命令

  cat是concatenate的缩写,即连接。
  cat命令用来连接多个文件并输出到标准输出。
  cat命令最常用的用法是显示文件的内容,其基本语法是:
    cat <文件名或文件全路径>
  例如,用来显示文件myfile1.txt的内容:

# cat myfile1.txt
This is content of myfile1.txt.

  cat命令也可以用来连接(合并)多个文件:

# cat myfile1.txt
This is content of myfile1.txt.
# cat myfile2.txt
This is content of myfile2.txt.
#
# cat myfile1.txt myfile2.txt
This is content of myfile1.txt.
This is content of myfile2.txt.
#
# cat myfile1.txt myfile2.txt > myfile3.txt
# cat myfile3.txt
This is content of myfile1.txt.
This is content of myfile2.txt.
#

  上面的例子使用cat命令来输出文件myfile1.txt和文件myfile2.txt的内容,还将两个文件的内容合并起来重定向到文件myfile3.txt,最后输出文件myfile3.txt的内容。