「Tee」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(create)
 
(序文を飜訳)
2行目: 2行目:
 
[[Category:コマンド]]
 
[[Category:コマンド]]
   
From [[Wikipedia:tee (command)|Wikipedia]]:
+
[[Wikipedia:tee (command)|Wikipedia]] より:
   
  +
:コンピュータでは、tee は標準ストリームを使用するコマンドラインインタプリタ(シェル)のコマンドで、標準入力を読み込んで標準出力と 1 つ以上のファイルの両方に書き込み、入力を効果的に複製するものです。主にパイプやフィルタと組み合わせて使用される。コマンド名は、配管工事で使用される T 字分岐にちなんで付けられた。
:In computing, tee is a command in command-line interpreters (shells) using standard streams which reads standard input and writes it to both standard output and one or more files, effectively duplicating its input. It is primarily used in conjunction with pipes and filters. The command is named after the T-splitter used in plumbing.
 
   
 
== Installation ==
 
== Installation ==

2022年6月8日 (水) 12:22時点における版

Wikipedia より:

コンピュータでは、tee は標準ストリームを使用するコマンドラインインタプリタ(シェル)のコマンドで、標準入力を読み込んで標準出力と 1 つ以上のファイルの両方に書き込み、入力を効果的に複製するものです。主にパイプやフィルタと組み合わせて使用される。コマンド名は、配管工事で使用される T 字分岐にちなんで付けられた。

Installation

tee(1) is part of the coreutils package.

Usage

To write content to files:

$ input stream | tee file1 file2...

By default, tee overwrites content in files when used again. However, if you want, you can append content in files by using the -a/--append argument.

For more usage, see tee(1).

Tips and tricks

Write to protected files

tee is very useful for writing to protected files:

$ input stream | sudo tee --option protected file1 protected file2...

when a simple >/>> would not have worked because of permissions.

Vim

Similar concept is useful when you forgot to start Vim with sudo when editing a configuration file owned by root. In this case you can do the following inside Vim to save the file:

:w !sudo tee %

You can add this to your ~/.vimrc to make this trick easy-to-use with :w!! mapping in command mode:

~/.vimrc
" Allow saving of files as sudo when I forgot to start vim using sudo
 cmap w!! w !sudo tee > /dev/null %

The > /dev/null part explicitly throws away the standard output since we do not need to pass anything to another piped command.

More detailed explanation of how and why this works can be found in How does the vim “write with sudo” trick work? article on StackOverflow.

See also