【问题标题】:Linux append console output to a logfile?Linux将控制台输出附加到日志文件?
【发布时间】:2012-07-14 01:02:49
【问题描述】:

我知道我可以让 Linux 将控制台输出写入日志文件:

command > logfile.log

但这会覆盖之前日志文件中的任何内容。如何让它将输出附加到日志文件而不是覆盖它?

【问题讨论】:

    标签: linux logging console


    【解决方案1】:

    单个大于字符 > 将输出写入文件。

    双字符>> 将输出追加到现有文件中

    【讨论】:

      【解决方案2】:

      几种方法:

      1) 使用io管道如下:

      $> echo 'some text' >> file.txt(将被附加)

      2) 使用类似 sed 的程序:

      $> 猫文件.txt

      一些文字

      $> sed -i '$ a\ here is some more text' file.txt(也将被附加,没有管道)

      Gl hf!

      【讨论】:

        【解决方案3】:

        您可以使用>> 附加到同一个日志文件 例如cmd1 >> logfile.log 然后用于其他命令,如

        cmd2 >> logfile.log
        

        >> 用于将数据追加到文件中

        【讨论】:

          【解决方案4】:

          使用command >> logfile.log

          【讨论】:

            【解决方案5】:

            只需将> 替换为>>

            【讨论】:

              【解决方案6】:

              更换运营商:

              command >> logfile.log
              

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2013-08-29
                • 1970-01-01
                • 1970-01-01
                • 2021-07-03
                • 1970-01-01
                相关资源
                最近更新 更多