tee
テキスト処理
書き方
[cmd] | tee [file]受け取ったものをファイルにも画面にも同時に流します。root 所有のファイルに書くにはこれで、sudo cmd > file の > は自分のシェルが開くからです。
よく使うオプション
| オプション | 意味 |
|---|---|
| -a | Append to the file instead of overwriting it |
| -i | Ignore Ctrl-C while the pipe runs |
| -p | GNU: report errors when writing to a pipe |
例
make 2>&1 | tee build.logWatch the build and keep a copy.
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.confAppends to a root-owned file, which > cannot do.
curl -s api | tee raw.json | jq .nameKeeps the raw body and reads one field.
パイプでつないで使うのが本来の形です。ひとつで全部やるより、三つつないだ方が短くなります。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. tee は何をしますか。
受け取ったものをファイルにも画面にも同時に流します。root 所有のファイルに書くにはこれで、sudo cmd > file の > は自分のシェルが開くからです。
Q. どう打ちますか。
[cmd] | tee [file] — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは3個です。全部は man tee にあります。このコマンドはテキスト処理の仲間です。
関連するコマンド
man ページ: man tee