Linux命令 - 覆盖 > 和 追加 >>
1.语法:
将列表的内容覆盖到文件中:ll >文件
将列表的内容追加到文件尾部:ll >>文件
将文件1的内容覆盖到文件2中:cat 文件1 > 文件2
将文件1的内容追加到文件2的尾部:cat 文件1 >> 文件2
将内容写入覆盖到文件中:echo “内容” > 文件
将内容写入追加到文件的尾部: echo “内容” >> 文件
2.功能:
指令 > : 如果文件存在,将原来文件的内容覆盖;原文件不存在则创建文件,再添加信息。
指令 >> : 不会覆盖原文件内容,将内容追加到文件的尾部。
[root@localhost test]# ll
总用量 28
-rw-r--r--. 2 root root 96 5月 18 10:15
lrwxrwxrwx. 1 root root 8 5月 18 14:57 linkcolor ->
-rw-r--r--. 2 root root 96 5月 18 10:15 lncolor
-rw-r--r--. 1 root root 156 5月 14 17:00
-rw-r--r--. 1 root root 592 5月 14 17:00
-rw-r--r--. 1 root root 655 5月 14 17:06
-rw-r--r--. 1 root root 156 5月 18 14:32
-rw-r--r--. 1 root root 272 5月 18 14:28
[root@localhost test]# rm -rf
[root@localhost test]# ll
总用量 24
lrwxrwxrwx. 1 root root 8 5月 18 14:57 linkcolor ->
-rw-r--r--. 1 root root 96 5月 18 10:15 lncolor
-rw-r--r--. 1 root root 156 5月 14 17:00
-rw-r--r--. 1 root root 592 5月 14 17:00
-rw-r--r--. 1 root root 655 5月 14 17:06
-rw-r--r--. 1 root root 156 5月 18 14:32
-rw-r--r--. 1 root root 272 5月 18 14:28
[root@localhost test]# touch
[root@localhost test]# ll
总用量 24
-rw-r--r--. 1 root root 0 5月 18 15:15
lrwxrwxrwx. 1 root root 8 5月 18 14:57 linkcolor ->
-rw-r--r--. 1 root root 96 5月 18 10:15 lncolor
-rw-r--r--. 1 root root 156 5月 14 17:00
-rw-r--r--. 1 root root 592 5月 14 17:00
-rw-r--r--. 1 root root 655 5月 14 17:06
-rw-r--r--. 1 root root 156 5月 18 14:32
-rw-r--r--. 1 root root 272 5月 18 14:28
[root@localhost test]# cat linkcolor
[root@localhost test]# cat lncolor
echo -e "\033[35mHello World\033[0m"
echo -e "\033[46;37mHello World\033[0m"
echo "Hello World"
3.常用范例:
例一:将ls查看信息写入到文件中
命令:ll >
[root@localhost test]# cat
Hello World
Hello World2
[root@localhost test]# ll
总用量 20
-rw-r--r--. 1 root root 96 5月 18 10:15
-rw-r--r--. 1 root root 156 5月 14 17:00
-rw-r--r--. 1 root root 592 5月 14 17:00
-rw-r--r--. 1 root root 655 5月 14 17:06
-rw-r--r--. 1 root root 25 5月 18 10:22
[root@localhost test]# ll >
[root@localhost test]# cat
总用量 16
-rw-r--r--. 1 root root 96 5月 18 10:15
-rw-r--r--. 1 root root 156 5月 14 17:00
-rw-r--r--. 1 root root 592 5月 14 17:00
-rw-r--r--. 1 root root 655 5月 14 17:06
-rw-r--r--. 1 root root 0 5月 18 14:28
例二:将的内容覆盖到中
命令:cat >
没有文件则会自动创建。
[root@localhost test]# cat
Thu Feb 25 09:46:34 2021
Create Relation ADR_CONTROL
Create Relation ADR_INVALIDATION
Create Relation INC_METER_IMPT_DEF
Create Relation INC_METER_PK_IMPTS
[root@localhost test]# ll
总用量 20
-rw-r--r--. 1 root root 96 5月 18 10:15
-rw-r--r--. 1 root root 156 5月 14 17:00
-rw-r--r--. 1 root root 592 5月 14 17:00
-rw-r--r--. 1 root root 655 5月 14 17:06
-rw-r--r--. 1 root root 272 5月 18 14:28
[root@localhost test]# cat >
[root@localhost test]# ll
总用量 24
-rw-r--r--. 1 root root 96 5月 18 10:15
-rw-r--r--. 1 root root 156 5月 14 17:00
-rw-r--r--. 1 root root 592 5月 14 17:00
-rw-r--r--. 1 root root 655 5月 14 17:06
-rw-r--r--. 1 root root 156 5月 18 14:32
-rw-r--r--. 1 root root 272 5月 18 14:28
[root@localhost test]# cat
Thu Feb 25 09:46:34 2021
Create Relation ADR_CONTROL
Create Relation ADR_INVALIDATION
Create Relation INC_METER_IMPT_DEF
Create Relation INC_METER_PK_IMPTS
例三:在追加内容
命令:echo Hello World2 >>
[root@localhost test]# cat
Hello World
[root@localhost test]# echo Hello World2 >>
[root@localhost test]# cat
Hello World
Hello World2
————————————————
版权声明:本文为****博主「EstherLty」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:/qq_45988641/article/details/116987515