Which of the following commands will send output from the program myapp to both standard output (stdout) and the file file1.log?

A.

cat < myapp | cat > file1.log

B.

myapp 0>&1 | cat > file1.log

C.

myapp | cat > file1.log

D.

myapp | tee file1.log

E.

tee myapp file1.log

题解

选项 A,这个指令会将「myapp」文件拷贝,并存成「file1.log」文件。

选项 B,「0」指的是标准输入串流(stdin),这个指令很明显有误。

选项 C,这个指令会将「myapp」输出的数据作为「cat」指令的输入,接着 cat 会再将输入的数据输出至「file1.log」文件中。

选项 D,这个指令会将「myapp」输出的数据作为「tee」指令的输入,「tee」指令可以将输入数据同时导给标准输出串流(stdout)和文件,所以这行指令符合题目要求,是正确答案。

选项 E,「tee」指令的用法错误。