![](/img/trans.png)
[英]Redirect output and error in to both logfile and console in #/bin/sh
[英]Linux append console output to a logfile?
我知道我可以让 Linux 通过执行以下操作将控制台输出写入日志文件:
command > logfile.log
但这会覆盖之前日志文件中的任何内容。 如何让它将输出附加到日志文件而不是覆盖它?
您可以使用>>
附加到相同的日志文件,例如cmd1 >> logfile.log
然后用于其他命令,例如
cmd2 >> logfile.log
>>
用于向文件追加数据
只需将>
替换为>>
更改运营商:
command >> logfile.log
使用command >> logfile.log
几种方式:
1)使用io管道如下:
$> echo 'some text' >> file.txt (将附加)
2) 使用类似 sed 的程序:
$> 猫文件.txt
一些文字
$> sed -i '$ a\ here is some more text' file.txt (也将附加,没有管道)
高频!
单个大于字符>
WRITES 输出到文件。
双字符>>
将输出附加到现有文件中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.