3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

teeコマンドを使っtee

Posted at

teeコマンドをつかってますか?

teeコマンドは,標準出力に吐き出しながらファイルに吐き出してくれるスグレモノです.

個人的に使っているTipsを紹介します.

sudoでファイルに書き出す

例えば,example.confのコメントを取り除いた設定ファイル example.conf.simpleを作成したい場合

sudo grep -v "^#" example.conf > example.conf.simple

このディレクトリに一般ユーザの書き込み権限がないと怒られます.

よくある方法はsudoでシェルを呼び出しでコマンド全体の実行です.

sudo sh -c 'grep -v "^#" example.conf > example.conf.simple'

これをteeで書き直してみると...

grep -v "^#" example.conf | sudo tee example.conf.simple

クリップボードの内容をsudoでファイルに書き出し

Configの流し込みに使えます.

sudo tee /etc/example.conf
hoge:
  fuga: 100
  foobar: 2000
[Ctrl + D]

sudoでファイルに追記

-a を使うと追記ができます.リダイレクトの >> で書かれているものは置換できます.

find /opt | sudo tee -a /etc/example.list
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?