[原文] .TH XARGS 1 \" -*- nroff -*- [訳文] .TH XARGS 1 ---------------------------------------- [原文] .SH NAME xargs - build and execute command lines from standard input [訳文] .SH 名前 xargs - 標準入力を読み込んでコマンドラインを作成し実行する ---------------------------------------- [原文] .SH SYNOPSIS .B xargs .nh [options] [command [initial-arguments]] .hy . [訳文] .SH 書式 xargs .nh [options] [command [initial-arguments]] .hy . ---------------------------------------- [原文] .SH DESCRIPTION This manual page documents the GNU version of .BR xargs . .B xargs reads items from the standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or newlines, and executes the .I command (default is .IR /bin/echo ) one or more times with any .I initial-arguments followed by items read from standard input. Blank lines on the standard input are ignored. [訳文] .SH 説明 このマニュアルページは GNU 版 xargs の使用法を説明しています。 xargs は、標準入力から空白や改行で区切られた一連の項目を読み込み (空白はダブルクォート、シングルクォート、バックスラッシュに よって保護できます)、 これを引数にして、 指定した command を 1 回以上実行する (デフォルトのコマンドは /bin/echo です)。 このとき、ユーザーが command に対して指定した引数 (上記書式の initial-arguments) があれば、 標準入力から読み込んだ一連の項目は、その後ろに追加されます。 標準入力における空行は無視されます。 ---------------------------------------- [原文] .P The command line for .I command is built up until it reaches a system-defined limit (unless the .B -n and .B -L options are used). The specified .I command will be invoked as many times as necessary to use up the list of input items. In general, there will be many fewer invocations of .I command than there were items in the input. This will normally have significant performance benefits. Some commands can usefully be executed in parallel too; see the .B -P option. [訳文] .P command のコマンドラインは、 (-n や -L オプションが使用されていない場合は) システムが定めているコマンドラインの長さの限界に達するまで、 長いものが作成されます。 そして、指定された command が、入力項目のリストを一つ残らず処理するのに必要な回数だけ、 呼び出されます。 だから、おおむね、command が呼び出される回数は、入力項目の数よりも、ずっと少なくてすむ わけだ。 このことは、たいていの場合、パフォーマンスを著しく向上させる ことになる。 なお、コマンドの中には、都合がよいことに、並列的に実行できる ものもある。-P オプションを参照していただきたい。 ---------------------------------------- [原文] .P Because Unix filenames can contain blanks and newlines, this default behaviour is often problematic; filenames containing blanks and/or newlines are incorrectly processed by .BR xargs . In these situations it is better to use the .B -0 option, which prevents such problems. When using this option you will need to ensure that the program which produces the input for .B xargs also uses a null character as a separator. If that program is GNU .B find for example, the .B -print0 option does this for you. [訳文] .P Unix では、 ファイル名に空白や改行を含むことが可能なので、 こうしたデフォルトの動作は、しばしば問題となります。 空白や改行を含むファイル名は、 xargs によって適切に処理されません。 このような状況では、-0 オプションの利用をお勧めします。 これを用いれば問題を回避できます。 なお、-0 オプションを使う場合は、xargs の入力を生成するプログラム側でも、 区切り文字にヌル文字を使うようにする必要があります。 たとえば GNU find を使う場合ば、 -print0 オプションを用いることになります。 ---------------------------------------- [原文] .P If any invocation of the command exits with a status of 255, .B xargs will stop immediately without reading any further input. An error message is issued on stderr when this happens. . [訳文] .P 指定したコマンドの実行が、 終了ステータス 255 で終了すると、 xargs は即座に停止して、それ以上入力を読み込みません。 このときには、エラーメッセージを標準エラーに出力します。 . ---------------------------------------- [原文] .SH OPTIONS [訳文] .SH オプション ---------------------------------------- [原文] .TP .B -0, --null Input items are terminated by a null character instead of by whitespace, and the quotes and backslash are not special (every character is taken literally). Disables the end of file string, which is treated like any other argument. Useful when input items might contain white space, quote marks, or backslashes. The GNU find -print0 option produces input suitable for this mode. [訳文] .TP -0, --null 入力される項目が、ホワイトスペース (空白や改行) ではなく、ヌル文字によって区切られます。 また、クォートやバックスラッシュは、 特別な扱いをしません (つまり、すべての文字がそのままに解釈されます)。 ファイル終端文字列は無効になり、他の引数と同じように扱われま す。 このオプションは、 入力される項目にホワイトスペース、クォート、バックスラッシュ などが含まれる可能性がある場合に、役に立ちます。 GNU find の -print0 オプションは、このモードに適した入力を生成します。 ---------------------------------------- [原文] .TP .BI "-a " file ", --arg-file=" file Read items from .I file instead of standard input. If you use this option, stdin remains unchanged when commands are run. Otherwise, stdin is redirected from .IR /dev/null . [訳文] .TP -a file, --arg-file=file 入力項目を、 標準入力からではなく file から読み込みます。 デフォルトでは、 指定したコマンドが実行される際に、 標準入力が /dev/null に付け換えられるが、 このオプションを使用した場合は、標準入力の付け換えが起こらな い。 ---------------------------------------- [原文] .TP .BI "--delimiter=" delim ", -d" " delim" Input items are terminated by the specified character. The specified delimiter may be a single character, a C-style character escape such as .BR \en , or an octal or hexadecimal escape code. Octal and hexadecimal escape codes are understood as for the .B printf command. Multibyte characters are not supported. When processing the input, quotes and backslash are not special; every character in the input is taken literally. The .B -d option disables any end-of-file string, which is treated like any other argument. You can use this option when the input consists of simply newline-separated items, although it is almost always better to design your program to use .B --null where this is possible. [訳文] .TP --delimiter=delim, -d delim 入力される一連の項目が、指定された文字によって区切られること になる。 指定される区切り文字は、単一の文字でもよく、\en のような C 言語式のエスケープ文字でも、8 進数や 16 進数のエスケープコードでもよい。 8 進数や 16 進数のエスケープコードは、printf コマンドの場合と同様に解釈される。 マルチバイト文字には対応していない。 入力を処理する際、クォートやバックスラッシュは特別扱いされな い。 すなわち、入力中のあらゆる文字が、文字通りに解釈される。 -d オプションを指定すると、ファイル終端文字列は無効になり、(xar gs が作成するコマンドラインにおいて) 他の引数と同じように扱われる。 入力が、項目を改行で区切っているだけのような単純な構成の場合 には、 このオプションを使ってもよいが、ほとんどたいていの場合、なる べくなら、xargs の --null を使うように、出力側のプログラムを組み立てる方が望ましい。 ---------------------------------------- [原文] .TP .BI -E " eof-str" Set the end of file string to eof-str. If the end of file string occurs as a line of input, the rest of the input is ignored. If neither .B -E nor .B -e is used, no end of file string is used. [訳文] .TP -E eof-str eof-str をファイル終端文字列として設定する。 ファイル終端文字列が入力中の 1 行として現れると、それ以後の入力は無視される。 -E も -e も指定しない場合、ファイル終端文字列は使用されない。 ---------------------------------------- [原文] .TP .BR -e "[eof-str], " "--eof" [=eof-str] This option is a synonym for the .B -E option. Use .B -E instead, because it is POSIX compliant while this option is not. If eof-str is omitted, there is no end of file string. If neither .B -E nor .B -e is used, no end of file string is used. [訳文] .TP -e[eof-str], --eof[=eof-str] このオプションは -E オプションの同義語である。-E の方を使っていただきたい。 理由は、そちらが POSIX に準拠しているのに対して、こちらは準拠していないからだ。 eof-str の部分が省略されると、ファイル終端文字列が存在しないことにな る。 -E も -e も指定しない場合、ファイル終端文字列は使用されない。 ---------------------------------------- [原文] .TP .BI -I " replace-str" Replace occurrences of replace-str in the initial-arguments with names read from standard input. Also, unquoted blanks do not terminate input items; instead the separator is the newline character. Implies .B -x and .B -L 1. [訳文] .TP -I replace-str initial-arguments 中で文字列 replace-str が現れるすべての箇所を、標準入力から読み込んだ名前で置き換え る。 なお、標準入力中にクォートされていない空白があっても、それは 入力項目の区切りにはならない。 区切り文字は改行文字だけになる。 -x と -L 1 の指定を暗に含む。 ---------------------------------------- [原文] .TP .BR -i "[replace-str], " "--replace" [=replace-str] This option is a synonym for .BI -I replace-str if .I replace-str is specified. If the .I replace-str argument is missing, the effect is the same as .BR -I {}. This option is deprecated; use .B -I instead. [訳文] .TP -i[replace-str], --replace[=replace-str] このオプションは、 replace-str が指定されていれば、-Ireplace-str の同義である。引数 replace-str が省略されていれば、-I{} と同じことになる。 このオプションは非推奨である。-I を使った方がよい。 ---------------------------------------- [原文] .TP .BI -L " max-lines" Use at most max-lines nonblank input lines per command line. Trailing blanks cause an input line to be logically continued on the next input line. Implies .BR -x . [訳文] .TP -L max-lines 1 コマンドラインにつき最大 max-lines 行の (空行ではない) 入力行を使用する。 入力行の行末に空白文字が付いていると、その行は次の入力行に論 理的に続いていることになる。 -x の指定を暗に含む。 ---------------------------------------- [原文] .TP .BR -l "[max-lines], " --max-lines "[=max-lines]" Synonym for the .B -L option. Unlike .BR -L , the .I max-lines argument is optional. If .I max-lines is not specified, it defaults to one. The .B -l option is deprecated since the POSIX standard specifies .B -L instead. [訳文] .TP -l[max-lines], --max-lines[=max-lines] -L オプションの同義語である。-L とは違って、max-lines という引数を指定するかどうかは任意である。引数 max-lines を指定しなかった場合は、デフォルトの 1 が使用される。POSIX 規格では -L の方を使うことになっているので、-l オプションの使用はお勧めできない。 ---------------------------------------- [原文] .TP .BI -n " max-args, \fI" "--max-args" =\fImax-args Use at most max-args arguments per command line. Fewer than .I max-args arguments will be used if the size (see the .B -s option) is exceeded, unless the .B -x option is given, in which case .B xargs will exit. [訳文] .TP -n max-args, --max-args=max-args 1 コマンドラインにつき最大 max-args 個の引数を使用する。 作成されたコマンドラインが、コマンドライン長の上限を超過する 場合は (-s オプション参照)、max-args より少ない引数が使用されることになる。 ただし、-x オプションが指定されているときは別で、その場合は xargs が終了する。 ---------------------------------------- [原文] .TP .BI -P " max-procs\fR, " --max-procs "=\fImax-procs" Run up to .I max-procs processes at a time; the default is 1. If .I max-procs is 0, .B xargs will run as many processes as possible at a time. Use the .B -n option or the .B -L option with .BR -P ; otherwise chances are that only one exec will be done. While .B xargs is running, you can send its process a SIGUSR1 signal to increase the number of commands to run simultaneously, or a SIGUSR2 to decrease the number. You cannot increase it above an implementation-defined limit (which is shown with --show-limits). You cannot decrease it below 1. .B xargs never terminates its commands; when asked to decrease, it merely waits for more than one existing command to terminate before starting another. [訳文] .TP -P max-procs, --max-procs=max-procs 同時に実行するプロセスの最大数を max-procs にする。デフォルトは 1 である。 max-procs が 0 だと、xargs はできるだけ多くのプロセスを同時に実行しようとする。 -P オプションには、-n か -L オプションを併せて使用するべきだ。 さもないと、おそらく exec 関数がたった一回しか実行されないことになるだろう。 xargs の実行中に、そのプロセスに SIGUSR1 シグナルを送れば、同時に実行するコマンドの数を増やすことがで きる。 また、SIGUSR2 シグナルを送れば、その数を減らすことができる。 ただし、実装が決めている上限を越えて増やすことはできないし (上限は --show-limits を使えば、知ることができる)、1 より少なくすることもできない。 xargs は、実行しているコマンドを終了させるわけではない。 実行数を減らすように命じられたときは、単に現在動いているコマ ンドが二つ以上終了するのを待ち、 それから別のコマンドを開始するのである。 ---------------------------------------- [原文] .B Please note that it is up to the called processes to properly manage parallel access to shared resources. For example, if more than one of them tries to print to stdout, the output will be produced in an indeterminate order (and very likely mixed up) unless the processes collaborate in some way to prevent this. Using some kind of locking scheme is one way to prevent such problems. In general, using a locking scheme will help ensure correct output but reduce performance. If you don't want to tolerate the performance difference, simply arrange for each process to produce a separate output file (or otherwise use separate resources). [訳文] 注意していただきたいが、共有リソースに対する並列アクセスをき ちんと管理するのは、呼び出されるプロセス側の問題である。 たとえば、複数のプロセスが標準出力に書き出そうとした場合、出 力順は不定である (そして混じり合ってしまうことが多い)。 そうならないためには、プロセス同士が何らかの形で協力し合う必 要がある。 ロックスキーム (locking scheme) のようなものを使うのは、そうした問題を避けるための一方法であ る。 ただ一般にロックスキームを使っても、出力順は適切に保証してく れるものの、パフォーマンスは低下する。 パフォーマンスが落ちるのが嫌ならば、単純に各プロセスがそれぞ れ別の出力ファイルを作るように (あるいは別のリソースを使うように) すればよい。 ---------------------------------------- [原文] .TP .B -o, --open-tty Reopen stdin as .I /dev/tty in the child process before executing the command. This is useful if you want .B xargs to run an interactive application. [訳文] .TP -o, --open-tty コマンド実行に先がけて、子プロセスにおいて stdin を /dev/tty として再オープンする。これは xargs を使って対話型アプリケーションを実行する場合に有用である。 ---------------------------------------- [原文] .TP .B -p, --interactive Prompt the user about whether to run each command line and read a line from the terminal. Only run the command line if the response starts with `y' or `Y'. Implies .BR -t . [訳文] .TP -p, --interactive コマンドライン 1 行ごとに、実行するかどうかをユーザーに尋ねるプロンプトを出し 、端末から 1 行読み込む。コマンドラインを実行するのは、 返答が `y' または `Y' で 始まるときだけである。自動的に -t が指定される。 ---------------------------------------- [原文] .TP .BR --process-slot-var "=name" Set the environment variable .I name to a unique value in each running child process. Values are reused once child processes exit. This can be used in a rudimentary load distribution scheme, for example. [訳文] .TP --process-slot-var=name 複数の子プロセスを同時実行しているとき、その各子プロセスで環 境変数 name にユニークな値をセットする。値は、子プロセスが終了すると、再 利用される。この機能は、たとえば、初歩的な負荷分散スキームで 利用できる。 ---------------------------------------- [原文] .TP .B -r, --no-run-if-empty If the standard input does not contain any nonblanks, do not run the command. Normally, the command is run once even if there is no input. This option is a GNU extension. [訳文] .TP -r, --no-run-if-empty 標準入力に空白しか含まれていない場合は、指定したコマンドを実 行しない。 通常では、入力が全くない場合でも、コマンドが一回は実行される のである。 このオプションは GNU の拡張である。 ---------------------------------------- [原文] .TP .BI -s " max-chars\fR, " --max-chars "=\fImax-chars" Use at most max-chars characters per command line, including the command and initial-arguments and the terminating nulls at the ends of the argument strings. The largest allowed value is system-dependent, and is calculated as the argument length limit for exec, less the size of your environment, less 2048 bytes of headroom. If this value is more than 128KiB, 128Kib is used as the default value; otherwise, the default value is the maximum. 1KiB is 1024 bytes. .B xargs automatically adapts to tighter constraints. [訳文] .TP -s max-chars, --max-chars=max-chars 1 コマンドラインにつき最大 max-chars の文字を使用する。 この文字数には、指定したコマンドと initial-arguments、それに各引数文字列の終端を示すヌル文字も 含まれる。 指定できる値の上限は、システム次第であり、exec 関数に対する引数の最大長から、現在の環境のサイズと 2048 バイトの余裕領域を引いたものである。もしその値が 128KiB 以上だったときは、デフォルトの値には 128KiB が使用される。 128KiB 未満のときは、算出された上限がデフォルトの値になる。 1KiB は 1024 バイトである。制限がより厳しい場合でも、xarg は自動的にそれに対応する。 ---------------------------------------- [原文] .TP .B "--show\-limits" Display the limits on the command-line length which are imposed by the operating system, .BR xargs ' choice of buffer size and the .B -s option. Pipe the input from .I /dev/null (and perhaps specify .BR --no-run-if-empty ) if you don't want .B xargs to do anything. [訳文] .TP --show-limits コマンドライン長の上限を表示する。コマンドライン長の上限は、 オペレーティングシステム、xargs が設定したバッファサイズ、それに -s オプションによって決まる。xargs にコマンドライン長の上限の表示以外をさせたくなかったら、 入力を /dev/null からパイプで xargs に渡してやればよい (さらに --no-run-if-empty を指定した方がよいかもしれない)。 ---------------------------------------- [原文] .TP .B -t, --verbose Print the command line on the standard error output before executing it. [訳文] .TP -t, --verbose 実行する前に、コマンドラインを標準エラー出力に表示する。 ---------------------------------------- [原文] .TP .B -x, --exit Exit if the size (see the .B -s option) is exceeded. [訳文] .TP -x, --exit 作成されたコマンドラインがコマンドライン長の上限を超過してい たら (-s オプションを参照)、終了する。 ---------------------------------------- [原文] .TP .B "--help" Print a summary of the options to .B xargs and exit. [訳文] .TP --help xargs のオプションについて簡単に説明し終了する。 ---------------------------------------- [原文] .TP .B "--version" Print the version number of .B xargs and exit. [訳文] .TP --version xargs のバージョン番号を表示して、終了する。 ---------------------------------------- [原文] .PP The options .B --max-lines (-L, -l), .B --replace (-I, -i) and .B --max-args (-n) are mutually exclusive. If some of them are specified at the same time, then .B xargs will generally use the option specified last on the command line, i.e., it will reset the value of the offending option (given before) to its default value. Additionally, .B xargs will issue a warning diagnostic on .IR stderr . The exception to this rule is that the special .I max-args value .I 1 ('-n1') is ignored after the .B --replace option and its aliases .B -I and .BR -i , because it would not actually conflict. [訳文] .PP オプション --max-lines (-L, -l)、--replace (-I, -i)、--max-args (-n) は同時に指定することはできない。これらを同時に指定した場合、 通常 xargs は、コマンドライン上の最後に指定されたオプションを利用する。 つまり誤って指定された (最終分よりも前に指定された) オプション値はデフォルトにリセットされる。さらに xargs は警告情報を stderr に出力する。この仕様には例外があり、max-args に対して特別な値 1 ('-n1') を指定した場合、--replace オプションおよびその別名である -I と -i の後ろであれば、max-args は無視される。これは相反する指定にならないからである。 ---------------------------------------- [原文] . [訳文] . ---------------------------------------- [原文] .SH "EXAMPLES" .nf .B find /tmp -name core -type f -print | xargs /bin/rm -f [訳文] .SH 例 .nf find /tmp -name core -type f -print | xargs /bin/rm -f ---------------------------------------- [原文] .fi Find files named .B core in or below the directory .B /tmp and delete them. Note that this will work incorrectly if there are any filenames containing newlines or spaces. [訳文] .fi /tmp ディレクトリ以下に core という名前のファイルを探して、それを消去する。 改行や空白を含むファイル名があると、正しく動作しないので、注 意すること。 ---------------------------------------- [原文] .P .B find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f [訳文] .P find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f ---------------------------------------- [原文] Find files named .B core in or below the directory .B /tmp and delete them, processing filenames in such a way that file or directory names containing spaces or newlines are correctly handled. [訳文] /tmp ディレクトリ以下に core という名前のファイルを探して、それを消去する。 ファイル名の処理に当たっては、ファイル名やディレクトリ名に空 白や改行が含まれていても、適切に扱われるようにしている。 ---------------------------------------- [原文] .P .B find /tmp -depth -name core -type f -delete [訳文] .P find /tmp -depth -name core -type f -delete ---------------------------------------- [原文] Find files named .B core in or below the directory .B /tmp and delete them, but more efficiently than in the previous example (because we avoid the need to use .BR fork (2) and .BR exec (2) to launch .B rm and we don't need the extra .B xargs process). [訳文] /tmp ディレクトリ以下に core という名前のファイルを探して、それを消去する。 上の例よりもこちらの方が効率的である (なぜなら、 rm を実行するために fork(2) と exec(2) を使わないですむし、そもそも、 xargs のプロセスを必要としないから)。 ---------------------------------------- [原文] .P .nf .B cut -d: -f1 < /etc/passwd | sort | xargs echo [訳文] .P .nf cut -d: -f1 < /etc/passwd | sort | xargs echo ---------------------------------------- [原文] .fi Generates a compact listing of all the users on the system. . [訳文] .fi システムの全ユーザーを列挙した簡潔なリストを生成する。 . ---------------------------------------- [原文] .SH "EXIT STATUS" .B xargs exits with the following status: [訳文] .SH 終了ステータス xargs の終了ステータスは以下のとおりである。 ---------------------------------------- [原文] .RS [訳文] .RS ---------------------------------------- [原文] .IP 0 if it succeeds [訳文] .IP 0 成功した。 ---------------------------------------- [原文] .IP 123 if any invocation of the command exited with status 1-125 [訳文] .IP 123 指定したコマンドの実行が 1-125 のステータスで終了した。 ---------------------------------------- [原文] .IP 124 if the command exited with status 255 [訳文] .IP 124 指定したコマンドが 255 のステータスで終了した。 ---------------------------------------- [原文] .IP 125 if the command is killed by a signal [訳文] .IP 125 指定したコマンドがシグナルによって kill された。 ---------------------------------------- [原文] .IP 126 if the command cannot be run [訳文] .IP 126 指定したコマンドが実行できない。 ---------------------------------------- [原文] .IP 127 if the command is not found [訳文] .IP 127 指定したコマンドが見つからない。 ---------------------------------------- [原文] .IP 1 if some other error occurred. [訳文] .IP 1 上記以外のエラーが起きた。 ---------------------------------------- [原文] .RE [訳文] .RE ---------------------------------------- [原文] .P Exit codes greater than 128 are used by the shell to indicate that a program died due to a fatal signal. . [訳文] .P 128 以上の終了ステータスは、致命的なシグナルのせいでプログラムが 止まったことを示すために、シェルが使用している。 . ---------------------------------------- [原文] .SH "STANDARDS CONFORMANCE" As of GNU xargs version 4.2.9, the default behaviour of .B xargs is not to have a logical end-of-file marker. POSIX (IEEE Std 1003.1, 2004 Edition) allows this. [訳文] .SH 規格への準拠 GNU xargs version 4.2.9 以来、ファイルの論理的な終端を示す指標 (a logical end-of-file marker) を持たないのが、xargs のデフォルトになっている。このことは POSIX (IEEE Std 1003.1, 2004 Edition) で認められている。 ---------------------------------------- [原文] .P The -l and -i options appear in the 1997 version of the POSIX standard, but do not appear in the 2004 version of the standard. Therefore you should use -L and -I instead, respectively. [訳文] .P -l や -i オプションは 1997 年版の POSIX 規格には存在するが、 2004 年版の POSIX 規格には存在しない。従って、それぞれ -L や -I の方を使うべきである。 ---------------------------------------- [原文] .P The -o option is an extension to the POSIX standard for better compatibility with BSD. [訳文] .P -o オプションは POSIX 規格を拡張したものであり、BSD と互換性を図るためのものである。 ---------------------------------------- [原文] .P The POSIX standard allows implementations to have a limit on the size of arguments to the .B exec functions. This limit could be as low as 4096 bytes including the size of the environment. For scripts to be portable, they must not rely on a larger value. However, I know of no implementation whose actual limit is that small. The .B --show-limits option can be used to discover the actual limits in force on the current system. . [訳文] .P POSIX 規格は、実装に当たって、exec 関数に対する引数のサイズに上限を設けることを認めている。 そして、その上限は、環境のサイズも含めて、少なくとも 4096 バイトあればよいことになっている。 移植性のあるスクリプトを書こうと思ったら、これより大きいサイ ズを当てにしてはいけない。 もっとも、実際の上限がそんなに小さい実装に、筆者は出会ったこ とがないけれど。 --show-limits オプションを使えば、使用中のシステムで有効な実際の上限を知る ことができる。 . ---------------------------------------- [原文] .SH "BUGS" It is not possible for .B xargs to be used securely, since there will always be a time gap between the production of the list of input files and their use in the commands that .B xargs issues. If other users have access to the system, they can manipulate the filesystem during this time window to force the action of the commands .B xargs runs to apply to files that you didn't intend. For a more detailed discussion of this and related problems, please refer to the ``Security Considerations'' chapter in the findutils Texinfo documentation. The .B -execdir option of .B find can often be used as a more secure alternative. [訳文] .SH バグ xargs を安全に使うことはできません。 なぜなら、入力ファイルの一覧を作成する時間と、 xargs からの実行コマンドがその一覧を使用する時間との間に、 必ず差が発生するためです。 仮に、 他のユーザーがすでにシステムにアクセスしていたとして、 そのユーザーが、 その一瞬の隙にファイルシステムを操作して、xargs が実行するコマンドの動作を、こちらが意図していないファイルに 無理矢理向けてしまう、 といったことができてしまいます。この議論や、これに関連する問 題については、 findutils に含まれる Texinfo 文書の「Security Considerations」という章でもっと細かく述べているので、 参照してください。 なお、find の -execdir オプションは、 より安全な方法として xargs の代わりに利用されることがよくあります。 ---------------------------------------- [原文] When you use the .B -I option, each line read from the input is buffered internally. This means that there is an upper limit on the length of input line that .B xargs will accept when used with the .B -I option. To work around this limitation, you can use the .B -s option to increase the amount of buffer space that .B xargs uses, and you can also use an extra invocation of .B xargs to ensure that very long lines do not occur. For example: [訳文] -I オプションを使うと、標準入力から読み込まれた各行が、 内部的にバッファに保存されます。 つまり、-I オプションをつけたときに、 xargs が受けつける入力 1 行には、 長さの上限があるということです。 この制限を回避するには、 -s オプションを使って、 xargs が使用するバッファ領域のサイズを増やして対処します。 もう 1 つの xargs を追加で実行すれば、極端に長い行が発生しないようにできます。 たとえば以下です。 ---------------------------------------- [原文] .P .B somecommand | xargs -s 50000 echo | xargs -I '{}' -s 100000 rm '{}' [訳文] .P somecommand | xargs -s 50000 echo | xargs -I '{}' -s 100000 rm '{}' ---------------------------------------- [原文] .P Here, the first invocation of .B xargs has no input line length limit because it doesn't use the .B -i option. The second invocation of .B xargs does have such a limit, but we have ensured that it never encounters a line which is longer than it can handle. This is not an ideal solution. Instead, the .B -i option should not impose a line length limit, which is why this discussion appears in the BUGS section. The problem doesn't occur with the output of .BR find (1) because it emits just one filename per line. . [訳文] .P xargs の 1 つめの呼び出しでは、入力行の長さに上限はありません。 これは -I オプションを使っていないからです。 xargs の 2 つめの呼び出しには、上限設定がありますが、 処理できなくなるような 1 行は、入ってこないのが明らかです。こうすることが理想的な解決 法というわけではありません。 それよりも、 -I オプションが長さの制限を設けないでいる方が望ましいことです。 だからこそ、この問題を「バグ」セクションで説明しているわけで す。 なおこの問題は、 find(1) の出力では発生しません。 find は 1 行に 1 ファイル名しか出力しないためです。 . ---------------------------------------- [原文] .SH "REPORTING BUGS" GNU findutils online help: Report any translation bugs to [訳文] .SH バグ報告 GNU findutils オンラインヘルプ: 翻訳に関するバグ報告 ---------------------------------------- [原文] .PP Report any other issue via the form at the GNU Savannah bug tracker: [訳文] .PP その他の問題について GNU Savannah バグトラッカー経由での報告: ---------------------------------------- [原文] .RS [訳文] .RS ---------------------------------------- [原文] .RE General topics about the GNU findutils package are discussed at the .I bug-findutils mailing list: [訳文] .RE GNU findutils パッケージのメーリングリスト bug-findutils において議論されている全般的なトピック: ---------------------------------------- [原文] .RS [訳文] .RS ---------------------------------------- [原文] .RE . [訳文] .RE . ---------------------------------------- [原文] .SH COPYRIGHT Copyright © 1990-2021 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. . [訳文] .SH 著作権 Copyright © 1990-2021 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. . ---------------------------------------- [原文] .SH "SEE ALSO" .BR find (1), .BR kill (1), .BR locate (1), .BR updatedb (1), .BR fork (2), .BR execvp (3), .BR locatedb (5), .BR signal (7) [訳文] .SH 関連項目 find(1), kill(1), locate(1), updatedb(1), fork(2), execvp(3), locatedb(5), signal(7) ---------------------------------------- [原文] .PP Full documentation or available locally via: .B info xargs [訳文] .PP 完全なドキュメント またローカルにおいては info xargs により参照できます。 ----------------------------------------