Linux基础命令之 cat

cat 功能:- 查看文件内容

                 - 添加文件内容

                 - 快速创建文件并写入内容


1. cat 查看文件内容: cat  filename

参数:

-n (number) 由 1 开始对所有输出的行进行依次编号

-b 或 --number-nonblank 和 -n 相似,只不过对于空白行不编号

-s  (squeeze-blank) 当遇到有连续两行以上的空白行,就代换为一行的空白行

-v (show-nonprinting)

-A  (show-all) 默认就是此参数奏效

-e    (equivalent to -vE)

-E, (show-ends display $ at end of each line) 每行结尾都以 $ 符号结尾


2-1. cat  添加文件内容方法1:(注意的是此种情况下,在编辑文件时,所有的操作都由对应的编码来表示,比如删除操作,按下删除键时,不会对文本内容删除,只会在文本内容后面追加^H的编码;此编码不会对文本内容操作;写完后回车,然后Ctrl+c退出编辑,再查看文件内容,发现之前的删除的编码不见了!=======这就是说:此种操作下:注意几点:a.文件内容不能立即修改 b.添加内容完成后,要回车进入空行后在退出才能保存成功 c.若要操作的文件不存在,会自动创建相应文件)

[root@sc Command]# cat demoCat2

[root@sc Command]# cat >demoCat2

hello word ,^H

it is the first ....

^C

[root@sc Command]# cat demoCat2

hello word

it is the first ....

[root@sc Command]#

2-2. cat添加文件内容方法2:(此种方法需注意:a.若文件不存在,则自动创建  b.以EOF结束,或者STOP结束(其实此处的EOF或STOP 只是多数人都是用的,只是一种约定,此处的符号意义上是 分界符,可以写成自己喜欢的任意的字符或字符串!)但必须是成对的出现,EOF 开始,就必须对应EOF 结束,STOP也一样  c.也可以追加文件内容)

[root@sc Command]# cat >demoCat3 <<EOF

> it's the first script

> EOF

[root@sc Command]# cat demoCat3

it's the first script

[root@sc Command]#

////////////////////////////////////////////////////////////////////////////////////////////

[root@sc Command]# cat >>demoCat3 >> STOP

[root@sc Command]# cat demoCat3

HELLO WORD

it's the first script

HEEO,word

[root@sc Command]#

//////////////////////////////////////////////////////////////////////////////////////////

[root@sc Command]# cat >demoCat3

> STOP

> EOF

[root@sc Command]# cat demoCat3

HEEEEE

STOP

[root@sc Command]#

//////////////////////////////////////////////////////////////////////////////////////////

3. cat 合并(拷贝)文件(有重定向知识):  (注意a.若重定向文件不存在,则自动创建 b.可以覆盖文本>,也可以追加文本>>)

[root@sc Command]# cat demoCat1

hello,word

my name is cat

[root@sc Command]# cat demoCat2

hello word

it is the first ....

[root@sc Command]# cat demoCat4

cat: demoCat4: 没有那个文件或目录

[root@sc Command]# cat demoCat1 demoCat2 >demoCat4

[root@sc Command]# cat demoCat4

hello,word

my name is cat

hello word

it is the first ....

[root@sc Command]#

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容