summaryrefslogtreecommitdiff
path: root/static/v10/man1/xargs.1
blob: 704b1a64d390f5ea69ef2ed250529751a4a6d8f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
.TH XARGS 1
.SH NAME
xargs \- construct argument lists and execute command
.SH SYNOPSIS
.B xargs
[
.I option
]
[
.I command
[
.I initial-arguments
]
]
.SH DESCRIPTION
.I Xargs\^
combines the fixed
.I initial-arguments\^
with arguments read from standard input to execute the specified
.I command\^
one or more times.
.IR Command
.RF ( /bin/echo
by default)
is located according to environment variable
.LR PATH .
.PP
Arguments read from standard input are delimited by
white space (blanks, tabs, or new-lines).
However, single or double quotes may be used to
surround arguments that contain blanks or tabs, and
backslash
.L \e
may be used to quote single characters outside of quotes.
.PP
Normally the
.I initial-arguments\^
are followed by arguments read from standard input until an internal buffer is full, whereupon
.I command\^
is executed with the accumulated arguments.
This process is repeated
until there are no more arguments.
Options modify this rule:
.TP
.BI \-l n\^
.I Command\^
is executed upon reading each
.I n\^
(default 1)
nonempty lines from standard input.
Newlines preceded by blank or tab are not counted.
Option
.B \-x
is implied.
.TP
.BI \-i s\^
Insert mode:
.I command\^
is executed for each line from standard input,
taking the entire line as a single arg, inserting it in
.I initial-arguments\^
for each occurrence of
.IR s ,
.B {\|}
by default.
Blanks and tabs at the beginning of each line are thrown away.
Constructed arguments may not exceed 255 characters.
Option
.B \-x
is implied.
.TP
.BI \-n n\^
Execute
.I command\^
using as many standard input arguments as possible, up to
.I n\^
arguments maximum.
.TP
.B \-t
Trace mode: The
.I command\^
and each constructed argument list are echoed to file descriptor 2
just prior to their execution.
.TP
.B \-p
Prompt about whether to execute
.I command.
Trace mode
.RB ( \-t )
is turned on to print the command instance to be executed,
followed by
.BR ?.\|.\|. .
The command will be executed if and only if the
reply begins with 
.LR y .
.TP
.B \-x
Terminate if any argument list would be greater than
.I size\^
characters.
.TP
.BI \-s size\^
The maximum total size of each argument list is
.I size\^
characters, 470 by default.
.TP
.BI \-e eofstr\^
.I Eofstr\^
(
.L _
by default)
is the logical end-of-file string.
Normally
.I xargs\^
reads standard input up to a logical or an actual end-of-file.
Option
.B \-e
with no
.I eofstr
turns off logical end-of-file testing.
.PP
.I Xargs\^
will terminate if it receives a return code of
.B \-1
from,
or cannot execute,
.IR command .
.SH EXAMPLES
.TP
.L
ls $1 \|| xargs \-i \-t mv $1/{\|} $2/{\|}
Move all files from directory
.L $1
to directory
.LR $2 ,
and echo each move
command just before doing it.
.TP
.L
(logname; date; echo $0 $*) | xargs >>log
Combine the output of the parenthesized commands onto one line,
which is then echoed to the end of file
.LR log .
.TP
.L
ls | xargs \-p \-l ar r arch
Ask which files in the current directory are to be archived
and archive them one at a time.
.TP
.L
ls | xargs \-p \-l | xargs ar r arch
Same, but archive many at a time.
.TP
.L
echo $** | xargs \-n2 diff
Execute
.IR diff (1)
with successive
pairs of arguments originally typed as shell arguments.
.SH "SEE ALSO"
.IR sh (1), 
.IR apply (1)
.\"	@(#)xargs.1	6.2 of 9/2/83