Linux shell命令之cat,linuxshellcat


cat:查看文件的内容、连接文件、创建一个或多个文件和重定向输出到终端或文件  用法:cat [选项] [文件]

1. $ cat hello.txt

显示hello.txt文本文件中的内容

 

2. $ cat -n file

-n选项,可以显示文件的内容和行号

 

3. $ cat -b file

-b选项,与-n类似,但只标识非空白行的行号(空白行仍显示)

 

4. $ cat -e file

-e选项,将在每一行的末尾显示“$”字符,在需要将多行内容转换成一行时非常有用。

 

5. $ cat

只输入cat命令的话,它只是接收标准输入的内容并在标准输出中显示,所以在输入一行并按回车后会在接下来的一行显示相同的内容。

如:$ cat

hello world!

hello world!

$

重定向的话:

$ cat >hello

hello world!

              (ctrl+D组合键退出,输入的内容 hello world! 会写入到文件hello中)

$ cat hello

hello world!

$

重定向操作符有两个: >和>>,前者是内容覆盖,后者是在文件的最后追加。

 

6. 连接多个文件的内容到一个新文件

$ cat test test1 > test2

$ cat test2

结果将显示test和test1中的内容。 

 

相关内容