linux中>和>>的区别

时间:2020-02-01 19:31:47   收藏:0   阅读:104

 

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

 

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

第一次输入‘> 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
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!