Linux 将控制台输出附加到日志文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11483012/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 13:48:25  来源:igfitidea点击:

Linux append console output to a logfile?

linuxloggingconsole

提问by Wingblade

I know that I can let Linux to write the console output to a logfile by doing:

我知道我可以通过执行以下操作让 Linux 将控制台输出写入日志文件:

command > logfile.log

But this overwrites whatever was in the logfile before. How do I make it append the output to the logfile rather than overwriting it?

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

采纳答案by Omkant

You can use >>for appending to the same logfile for e.g cmd1 >> logfile.logthen use for other commnad like

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

cmd2 >> logfile.log

>>is used for append data to the file

>>用于将数据附加到文件

回答by arkascha

Change the operator:

更改运算符:

command >> logfile.log

回答by Mats

just replace >for >>

只需替换>>>

回答by Damien

Use command >> logfile.log

command >> logfile.log

回答by Peter M. Elias

A couple ways:

几种方式:

1) Uses io piping as follows:

1)使用io管道如下:

$> echo 'some text' >> file.txt (will be appended)

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

2) Using a program like sed:

2)使用像sed这样的程序:

$> cat file.txt

$> 猫文件.txt

some text

一些文字

$> sed -i '$ a\ here is some more text' file.txt (will also be appended, without piping)

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

Gl hf!

高频!

回答by Bantu Manjunath

A single greater than character >WRITES output to a file.

单个大于字符>WRITES 输出到文件。

A double character >>APPENDS output into an existing file

双字符>>APPENDS 输出到现有文件中