如何将 tee 附加到 Bash 中的文件?

Blu*_*eep 133 bash tee

这些是我在终端中输入的命令

echo -e "First Line" | tee ~/output.log
echo -e "Second Line" | tee ~/output.log
Run Code Online (Sandbox Code Playgroud)

当我查看文件 output.log 时,我只看到“第二行”。如何确保 tee 附加(而不是清除文件)?

我希望能够在文件中看到这一点:

First Line
Second Line
Run Code Online (Sandbox Code Playgroud)

我应该以另一种方式接近这个吗?

use*_*274 212

echo -e "First Line" | tee ~/output.log
echo -e "Second Line" | tee -a ~/output.log
                            ^^
Run Code Online (Sandbox Code Playgroud)

来自男士 T 恤

   Copy standard input to each FILE, and also to standard output.

   -a, --append
          append to the given FILEs, do not overwrite
Run Code Online (Sandbox Code Playgroud)

注意:使用-a仍然会创建提到的文件。

  • 为了搜索者的利益,-a 修饰符用于“追加”,或添加到末尾。如果没有 -a,tee 命令会覆盖文件。 (14认同)
  • @СашаЧерных 我不知道。对于一个新问题来说,这听起来是一个很好的主题! (3认同)
  • @Саша Черных 'cat source.file destination.file | tee destination.file' 将在 destination.file 的开头附加 source.file。这种方法的唯一问题是 tee 将打印到标准输出两个文件。 (2认同)