我需要将一个命令的输出重定向到两个文件中,file1是一个新文件,而file2是一个已经存在的文件,在其中我需要追加输出。我尝试过,但未得到预期结果。
command > file1 > file2
command > file1 > file2
你正在寻找tee
命令。
$ echo existing >file2
$ date | tee file1 >> file2
$ cat file2
existing
Mon Mar 9 10:40:01 CET 2009
$ cat file1
Mon Mar 9 10:40:01 CET 2009
$
对于Windows平台(cmd.exe):
command > file1 & type file1 >> file2
tee
的情况下,使用cmd.exe是不可能的。tee
在GNU实用程序的Windows端口中,比如git for Windows或Chef中都有,所以获取它并不是不可能的。答案的意图是编写某些东西来模拟cmd.exe中的此行为。其他人编写了Powershell变体。 - Tomalakcommand | tee -a file1 file2
tee-object
(或其tee
别名)command | tee first-file | out-file second-file
还可以将其输出到变量中(例如,以便进行进一步处理)。