【问题标题】:What is the difference between ">" and ">>" when using echo to write to file使用回显写入文件时“>”和“>>”有什么区别
【发布时间】:2016-03-15 11:56:51
【问题描述】:

看到这个问题时的后续问题How can I write and append using echo command to a file

我试图找到它应该已经得到回答,但显然要么它不存在,要么我找不到它。

我对在这个网站上发布问题真的很陌生(这是我的第一个问题!)

【问题讨论】:

    标签: linux file echo


    【解决方案1】:

    > 是“覆盖”,>> 是“附加”。前者会覆盖文件,后者会添加到最后。

    echo foo > file
    echo bar > file
    cat file
    # => bar
    
    echo foo > file
    echo bar >> file
    cat file
    # => foo
    #    bar
    

    【讨论】:

    • 我知道使用 > 会创建一个新文件,只是发现使用 >> 也可以!太棒了!
    猜你喜欢
    • 2013-06-10
    • 2011-11-09
    • 1970-01-01
    • 2015-10-16
    • 2015-05-25
    • 2014-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多