首页 > 系统服务 > 详细

linux中>和>>的区别

时间:2020-02-01 19:34:37      阅读:54      评论:0      收藏:0      [点我收藏+]

 

本文编写的目的是为了,方便自己日后查看。

 

  ‘>‘  输出到文件中。文件不存在会创建。文件已存在,内容会被覆盖。文件时间会更新。

第一次输入‘> test‘, 第二次输入‘> test again‘, 发现内容

[root@localhost ~]# echo ‘> test‘ > echo.log
[root@localhost ~]# ll
总用量 8
-rw-------. 1 root root 1555 8月  20 15:30 anaconda-ks.cfg
-rw-r--r--  1 root root    7 2月   1 18:03 echo.log
[root@localhost ~]# cat echo.log 
> test
[root@localhost ~]# echo ‘> test again‘ > echo.log
[root@localhost ~]# cat echo.log 
> test again
[root@localhost ~]# ll
总用量 8
-rw-------. 1 root root 1555 8月  20 15:30 anaconda-ks.cfg
-rw-r--r--  1 root root   13 2月   1 18:04 echo.log

最后输出只有:‘> test again‘ 

 

删除echo.log, 测试‘>>‘

 

‘>>‘输出到文件中。文件不存在会创建。文件已存在,内容会继续追加在后面。文件时间会更新。

[root@localhost ~]# rm echo.log 
rm:是否删除普通文件 "echo.log"?y
[root@localhost ~]# ll
总用量 4
-rw-------. 1 root root 1555 8月  20 15:30 anaconda-ks.cfg
[root@localhost ~]# echo ‘> test‘ >> echo.log
[root@localhost ~]# ll
总用量 8
-rw-------. 1 root root 1555 8月  20 15:30 anaconda-ks.cfg
-rw-r--r--  1 root root    7 2月   1 18:11 echo.log
[root@localhost ~]# cat echo.log 
> test
[root@localhost ~]# echo ‘> test again‘ >> echo.log
[root@localhost ~]# ll
总用量 8
-rw-------. 1 root root 1555 8月  20 15:30 anaconda-ks.cfg
-rw-r--r--  1 root root   20 2月   1 18:12 echo.log
[root@localhost ~]# cat echo.log 
> test
> test again

 

最后输出,文本中有两行。
> test > test again

linux中>和>>的区别

原文:https://www.cnblogs.com/chenmz1995/p/12249399.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!