「Tee」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(序文を飜訳)
(文言修正)
 
(同じ利用者による、間の9版が非表示)
1行目: 1行目:
 
{{Lowercase title}}
 
{{Lowercase title}}
 
[[Category:コマンド]]
 
[[Category:コマンド]]
  +
[[en:Tee]]
 
 
[[Wikipedia:tee (command)|Wikipedia]] より:
 
[[Wikipedia:tee (command)|Wikipedia]] より:
   
:コンピューでは、tee は標準ストリームを使用するコマンドラインインタプリタ(シェル)のコマンドで、標準入力を読み込んで標準出力と 1 つ以上のファイルの両方に書き込み、入力を効果的に複製するものです。主にパイプやフィルタと組み合わせて使用される。コマンド名は、配管工事で使用される T 字分岐にちなんで付けられ
+
:コンピューティングでは、tee は標準ストリームを使用するコマンドラインインタプリタ(シェル)のコマンドで、標準入力を読み込んで標準出力と 1 つ以上のファイルの両方に書き込み、入力を効果的に複製するものです。主にパイプやフィルタと組み合わせて使用される。コマンド名は、配管工事で使用される T 字分岐にちなんで付けられています
   
== Installation ==
+
== インストール ==
   
{{man|1|tee}} is part of the {{Pkg|coreutils}} package.
+
{{man|1|tee}} {{Pkg|coreutils}} パッケージの一部です。
   
== Usage ==
+
== 使い方 ==
   
  +
ファイルにコンテンツを書き込むには
To write content to files:
 
   
 
$ ''input stream'' | tee ''file1 file2...''
 
$ ''input stream'' | tee ''file1 file2...''
   
  +
デフォルトでは、tee は再度使用されると、ファイル内のコンテンツを上書きします。 ただし、必要に応じて、{{ic|-a}}/{{ic|--append}} 引数を使用してファイルにコンテンツを追加できます。
By default, tee overwrites content in files when used again. However, if you want, you can append content in files by using the {{ic|-a}}/{{ic|--append}} argument.
 
   
For more usage, see {{man|1|tee}}.
+
詳細は、{{man|1|tee}} を参照してください。
   
  +
== ヒントとテクニック ==
== Tips and tricks ==
 
   
  +
=== 保護されたファイルに書き込む ===
=== Write to protected files ===
 
   
  +
tee は保護されたファイルへの書き込みに非常に便利です。
tee is very useful for writing to protected files:
 
   
 
$ ''input stream'' | sudo tee ''--option'' ''protected file1 protected file2...''
 
$ ''input stream'' | sudo tee ''--option'' ''protected file1 protected file2...''
   
  +
パーミッションの関係で、単純な {{ic|>}}/{{ic|>>}} ではうまくいかなかった場合に。
when a simple {{ic|>}}/{{ic|>>}} would not have worked because of permissions.
 
   
 
=== Vim ===
 
=== Vim ===
   
  +
同様のコンセプトは、{{ic|root}} が所有する設定ファイルを編集する際に、[[sudo]] で [[Vim]] を起動するのを忘れた場合に便利です。この場合、[[Vim]] 内部で以下のようにしてファイルを保存することができます。
Similar concept is useful when you forgot to start [[Vim]] with [[sudo]] when editing a configuration file owned by {{ic|root}}. In this case you can do the following inside [[Vim]] to save the file:
 
   
 
:w !sudo tee %
 
:w !sudo tee %
   
  +
これを {{ic|~/.vimrc}} に追加すると、コマンドモードでの {{ic|:w!!!}} マッピングでこのトリックを簡単に使えるようになります。
You can add this to your {{ic|~/.vimrc}} to make this trick easy-to-use with {{ic|:w!!}} mapping in command mode:
 
   
 
{{hc|~/.vimrc|2=
 
{{hc|~/.vimrc|2=
43行目: 43行目:
 
}}
 
}}
   
  +
{{ic|> /dev/null}} の部分は、他のパイプコマンドに何も渡す必要がないため、標準出力を明示的に捨てています。
The {{ic|> /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 [https://stackoverflow.com/questions/2600783/how-does-the-vim-write-with-sudo-trick-work How does the vim “write with sudo” trick work?] article on StackOverflow.
+
この仕組みの詳細については、[https://stackoverflow.com/questions/2600783/how-does-the-vim-write-with-sudo-trick-work How does the vim “write with sudo” trick work?] の記事を参照してください。
   
== See also ==
+
== 参照 ==
   
 
* [https://www.gnu.org/software/coreutils/manual/html_node/tee-invocation.html tee info]
 
* [https://www.gnu.org/software/coreutils/manual/html_node/tee-invocation.html tee info]
  +
  +
{{TranslationStatus|tee|2022-7-5|736274}}

2022年7月5日 (火) 09:28時点における最新版

Wikipedia より:

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

インストール

tee(1)coreutils パッケージの一部です。

使い方

ファイルにコンテンツを書き込むには

$ input stream | tee file1 file2...

デフォルトでは、tee は再度使用されると、ファイル内のコンテンツを上書きします。 ただし、必要に応じて、-a/--append 引数を使用してファイルにコンテンツを追加できます。

詳細は、tee(1) を参照してください。

ヒントとテクニック

保護されたファイルに書き込む

tee は保護されたファイルへの書き込みに非常に便利です。

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

パーミッションの関係で、単純な >/>> ではうまくいかなかった場合に。

Vim

同様のコンセプトは、root が所有する設定ファイルを編集する際に、sudoVim を起動するのを忘れた場合に便利です。この場合、Vim 内部で以下のようにしてファイルを保存することができます。

:w !sudo tee %

これを ~/.vimrc に追加すると、コマンドモードでの :w!!! マッピングでこのトリックを簡単に使えるようになります。

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

> /dev/null の部分は、他のパイプコマンドに何も渡す必要がないため、標準出力を明示的に捨てています。

この仕組みの詳細については、How does the vim “write with sudo” trick work? の記事を参照してください。

参照

翻訳ステータス: このページは en:tee の翻訳バージョンです。最後の翻訳日は 2022-7-5 です。もし英語版に 変更 があれば、翻訳の同期を手伝うことができます。