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」指令的用法錯誤。