linux中 > 、>> 的用法

linux中>表示覆盖原文件内容(文件的日期也会自动更新),>>表示追加内容(会另起一行,文件的日期也会自动更新)。

 

1 将history命令执行的结果保存到history.log文件中

[root@gxzs-solr1 ~]# history > history.log      (history.log 文件 会自动生成)
[root@gxzs-solr1 ~]# cat history.log 

2 执行命令 curl 'xxx' ,将其返回结果保存到 log.log 中

[root@gx-solr1 ~]# curl 'http://192.168.0.110:8983/solr/scan_detail/admin/file?_=1544066402749&contentType=text/plain;charset=utf-8&file=managed-schema&wt=json' > log.log

3 执行命令 cat /etc/hosts , 将其返回结果保存到 hosts.log 中

[root@slave1 ~]# cat /etc/hosts > hosts.log
[root@slave1 ~]# more hosts.log 
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

注意:
使用  >   ,执行命令时,每次都会新生成一个 > 后面的文件,将之前生成的文件替换掉(文件创建时间也会跟着改变)。

 

4 使用 >> 向 hosts.log中追加 当前日期

[root@slave1 ~]# echo "当前日期是 `date`" >> hosts.log

[root@slave1 ~]# ls -l hosts.log 
-rw-r--r--. 1 root root 11 Dec 13 16:04 hosts.log # 查看hosts.log 的日期
[root@slave1 ~]# cat hosts.log                    # 查看hosts.log 文件的内容
 I am OK! 
[root@slave1 ~]# echo "当前日期是 `date`" >> hosts.log  # 向hosts.log中追加 当前日期
[root@slave1 ~]# cat hosts.log                    # 再次查看hosts.log 文件的内容
 I am OK! 
当前日期是 Thu Dec 13 16:05:18 CST 2018         
[root@slave1 ~]# ls -l hosts.log                  # 再次查看hosts.log 的日期
-rw-r--r--. 1 root root 56 Dec 13 16:05 hosts.log
[root@slave1 ~]# 

 

  • 49
    点赞
  • 154
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值