xargs.1
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 1 代码 · 共 245 行
1
245 行
.TH xargs 1.SH Namexargs \- construct argument list and execute command .SH Syntax.NXR "xargs command".B xargs[\fIflags\fR] [ \fIcommand\fR [\fIinitial-arguments\fR] ].SH DescriptionThe command.PN xargscombines fixed.I initial-argumentswith arguments read from standard input to execute a specified.I commandone or more times. The number of arguments read when a .I commandis invoked and how they are combinedis determined by the options specified..PPThe specified.I command,(which can be a Shell file)is searched for using ones' \fB$PATH\fR specification.If.I commandis not specified,.B /bin/echois used..PPArguments read from standard input are defined as contiguousstrings of characters delimited by one or more blanks, tabs, or newlines;empty lines are always discarded.Blanks and tabs can be embedded as part of an argument if they containan escape character or if they are quoted.Characters enclosed in quotes (single or double) are taken literally,and the delimiting quotes are removed; a backslash (\\)escapes the next character..SH OptionsEach argument list begins with the.IR initial-arguments,followed by arguments read from standard input, with the exceptionof the .B \-ioption. See the description of the .BR \-i option for more information..PPThe options.BR \-i ,.BR \-l ,and.BR \-ndetermine how arguments are selected when each command is invoked.If none of these options are specified, the.I initial-argumentsare followed by arguments read continuously from standard input until the internal buffer is full; then,.I commandexecutes with the accumulated arguments. This process repeatsuntil no arguments exist. When conflicts arise, suchas the .B \-loption used with the.BR \-n,the last option has precedence. The options values are as follows:.TP 6.BI \-l numberExecute .I command for each non-empty.I numberlines of arguments from standard input.When command is invoked for the final time, it has fewer lines of arguments if fewer than a specified.I numberremain.A line ends with the first newline unlessthe last character of the line is a blank or a tab;a trailing blank or tab signals continuation through the next non-empty line.If.I numberis is not specified, the value 1 is assumed.The option.B \-xis forced..TP 6\fB\-i\fR\fIreplstr\fR \fB(Insert mode)\fRExecute.I commandfor each line from standard input,taking the entire line as a single argument and inserting it in.I initial-arguments\^for each occurrence of.IR replstr .A maximum of five arguments specified in .I initial-argumentscan contain one or more occurrence of.IR replstr .Blanks and tabs at the beginning of each line are discarded.A constructed arguments cannot exceed 255 characters and the option.B \-xis a forced.A .B {|}is assumed for.I replstrif not specified..TP 6.BI \-n numberExecute.I commandusing as many standard input arguments as possible, up to the specified.I numberarguments maximum.Fewer arguments are used if their total size is greater than.I sizecharacters, and when the last command is invoked, fewer.I numberof arguments remain.If the option.B \-xis also include, each specified.I numberof arguments must fit in the.I sizelimitation, or else.I xargsterminates execution..TP 6.B \-t (Trace mode)Echo the.I command\^and each constructed argument list to file descriptor 2prior to their execution..TP 6.B \-p (Prompt mode)Asks the user whether or not .I command\^should be executed each time .I commandis invoked. Trace mode (\c.B \-t\c) is turned on to print the command instance to be executed,followed by a \fB?.\|.\|.\fP prompt.A reply of.B yexecutes the command; any other responsedoes not invoke that particular.IR command..TP 6.B \-xCauses the command.I xargsto terminate if an argument list is greater than the specified.I sizeof characters; the option.B \-xis forced by the options.B \-iand.BR \-l .When the options.BR \-i ,.BR \-l ,or.B \-nare included, the total length of all arguments must be within the specified.I sizelimit..TP 6.BI \-s sizeThe maximum size of each argument list is set to.I sizecharacters;.I sizemust be a positive integer less than or equal to 470. If.B \-sis not included, 470 is the default.Note that the character count for.I sizeincludes one extra character for each argument and the count of characters in the command name..TP 6.BI \-e eofstrThe option.I eofstris taken as the logical end-of-file string.Underscore (\|_\|) is assumed forthe logical \fB\s-1EOF\s+1\fR stringif \fB\-e\fR is not specified.The value\fB\-e\fR without.I eofstrspecified turns off the logical \fB\s-1EOF\s+1\fP string capability;the underscore is taken literally.The command.I xargsreads standard input until either end-of-file or the logical \fB\s-1EOF\s+1\fP string is encountered..PPThe command.I xargsterminates if it receives a return code of.B \-1from .IR command or if it cannot execute.IR command .When.I commandis a Shell program, it should explicitly.I exitwith an appropriate value to avoid returning with.BR \-1 .See .MS sh 1for more information..SH ExamplesThe following example moves all files from directory $1 to directory $2and echoes the move command prior to executing it:.PPls \|$1 \|| \|xargs \|\-i \|\-t \|mv \|$1/{\|} \|$2/{\|}.PPThe following example combines the output of the parenthesized commands onto one line, which is then echoed to the end of file \fIlog\fP:.PP(logname; \|date; \|echo \|$0 \|$\(**) \|| \|xargs \|>>log.PPIn the next example, the user is prompted to specify which files in thecurrent directory are to be archived. The first example archives thefiles one at a time; the second example archives groups of files:.PP\ \|\ \|ls \|| \|xargs \|\-p \|\-l \|ar \|r \|arch.sp\ \|\ \|ls \|| \|xargs \|\-p \|\-l \|| \|xargs \|ar \|r \|arch.PPThe following example executes.IR diff "(1)"with successivepairs of arguments originally typed as Shell arguments:.PPecho \|$\(** \|| \|xargs \|\-n2 \|diff.SH See Alsosh(1).
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?