問題
commandの出力をterminalへ表示し、同時に結果fileへも保存する基本のcommandはどれか。
- A
tee result.txt
- B
command >result.txtだけ
- C
xargs result.txt
- D
cut -d : -f 1
正解:A
理由
teeがstdinをfileとstdoutへ分岐する。
入力と結果
画面とファイルへ同じ2行を出す。
$ printf 'red\nblue\n' | tee copied.txt
red
blue
$ cat copied.txt
red
blue最初はteeの標準出力、後半は保存したファイルの内容。
選択肢ごとの説明
- A.
tee result.txt
fileとstdoutへ出す。
- B.
command >result.txtだけ
stdoutをfileへ向け、通常そのままterminalへは出さない。
- C.
xargs result.txt
引数の組立てで、出力を二箇所へ複製しない。
- D.
cut -d : -f 1
fieldの抽出である。