<s>
xargs	B-Application
(	O
short	O
for	O
"	O
extended	O
arguments	O
"	O
)	O
is	O
a	O
command	B-Application
on	O
Unix	B-Application
and	O
most	O
Unix-like	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
used	O
to	O
build	O
and	O
execute	O
commands	O
from	O
standard	B-Operating_System
input	I-Operating_System
.	O
</s>
<s>
It	O
converts	O
input	O
from	O
standard	B-Operating_System
input	I-Operating_System
into	O
arguments	O
to	O
a	O
command	B-Application
.	O
</s>
<s>
Some	O
commands	O
such	O
as	O
grep	B-Application
and	O
awk	B-Application
can	O
take	O
input	O
either	O
as	O
command-line	O
arguments	O
or	O
from	O
the	O
standard	B-Operating_System
input	I-Operating_System
.	O
</s>
<s>
However	O
,	O
others	O
such	O
as	O
cp	B-Application
and	O
echo	B-Application
can	O
only	O
take	O
input	O
as	O
arguments	O
,	O
which	B-Device
is	O
why	O
xargs	B-Application
is	O
necessary	O
.	O
</s>
<s>
A	O
port	O
of	O
an	O
older	O
version	O
of	O
GNU	B-Operating_System
is	O
available	O
for	O
Microsoft	B-Application
Windows	I-Application
as	O
part	O
of	O
the	O
UnxUtils	B-Application
collection	O
of	O
native	B-Language
Win32	B-Library
ports	O
of	O
common	O
GNU	B-Operating_System
Unix-like	B-Operating_System
utilities	O
.	O
</s>
<s>
A	O
ground-up	O
rewrite	O
named	O
is	O
part	O
of	O
the	O
open-source	B-Application
TextTools	O
project	O
.	O
</s>
<s>
The	O
command	B-Application
has	O
also	O
been	O
ported	O
to	O
the	O
IBM	B-Application
i	I-Application
operating	B-General_Concept
system	I-General_Concept
.	O
</s>
<s>
One	O
use	O
case	O
of	O
the	O
xargs	B-Application
command	B-Application
is	O
to	O
remove	O
a	O
list	O
of	O
files	O
using	O
the	O
rm	B-Application
command	B-Application
.	O
</s>
<s>
POSIX	O
systems	O
have	O
an	O
for	O
the	O
maximum	O
total	O
length	O
of	O
the	O
command	B-Application
line	O
,	O
so	O
the	O
command	B-Application
may	O
fail	O
with	O
an	O
error	O
message	O
of	O
"	O
Argument	O
list	O
too	O
long	O
"	O
(	O
meaning	O
that	O
the	O
exec	O
system	O
call	O
's	O
limit	O
on	O
the	O
length	O
of	O
a	O
command	B-Application
line	O
was	O
exceeded	O
)	O
:	O
or	O
.	O
</s>
<s>
This	O
can	O
be	O
rewritten	O
using	O
the	O
xargs	B-Application
command	B-Application
to	O
break	O
the	O
list	O
of	O
arguments	O
into	O
sublists	O
small	O
enough	O
to	O
be	O
acceptable	O
:	O
</s>
<s>
In	O
the	O
above	O
example	O
,	O
the	O
find	B-Application
utility	O
feeds	O
the	O
input	O
of	O
xargs	B-Application
with	O
a	O
long	O
list	O
of	O
file	O
names	O
.	O
</s>
<s>
xargs	B-Application
then	O
splits	O
this	O
list	O
into	O
sublists	O
and	O
calls	O
rm	B-Application
once	O
for	O
every	O
sublist	O
.	O
</s>
<s>
Some	O
implementations	O
of	O
xargs	B-Application
can	O
also	O
be	O
used	O
to	O
parallelize	O
operations	O
with	O
the	O
-P	O
maxprocs	O
argument	O
to	O
specify	O
how	O
many	O
parallel	B-Application
processes	O
should	O
be	O
used	O
to	O
execute	O
the	O
commands	O
over	O
the	O
input	O
argument	O
lists	O
.	O
</s>
<s>
xargs	B-Application
often	O
covers	O
the	O
same	O
functionality	O
as	O
the	O
command	B-Application
substitution	O
feature	O
of	O
many	O
shells	B-Application
,	O
denoted	O
by	O
the	O
backquote	O
notation	O
( `	O
...	O
`	O
or	O
$( 	O
...	O
)	O
)	O
.	O
</s>
<s>
xargs	B-Application
is	O
also	O
a	O
good	O
companion	O
for	O
commands	O
that	O
output	O
long	O
lists	O
of	O
files	O
such	O
as	O
find	B-Application
,	O
locate	B-Application
and	O
grep	B-Application
,	O
but	O
only	O
if	O
one	O
uses	O
-0	O
(	O
or	O
equivalently	O
--null	O
)	O
,	O
since	O
xargs	B-Application
without	O
-0	O
deals	O
badly	O
with	O
file	O
names	O
containing	O
'	O
,	O
"	O
and	O
space	O
.	O
</s>
<s>
GNU	B-Application
Parallel	I-Application
is	O
a	O
similar	O
tool	O
that	O
offers	O
better	O
compatibility	O
with	O
find	B-Application
,	O
locate	B-Application
and	O
grep	B-Application
when	O
file	O
names	O
may	O
contain	O
'	O
,	O
"	O
,	O
and	O
space	O
(	O
newline	O
still	O
requires	O
-0	O
)	O
.	O
</s>
<s>
The	O
xargs	B-Application
command	B-Application
offers	O
options	O
to	O
insert	O
the	O
listed	O
arguments	O
at	O
some	O
position	O
other	O
than	O
the	O
end	O
of	O
the	O
command	B-Application
line	O
.	O
</s>
<s>
The	O
-I	O
option	O
to	O
xargs	B-Application
takes	O
a	O
string	O
that	O
will	O
be	O
replaced	O
with	O
the	O
supplied	O
input	O
before	O
the	O
command	B-Application
is	O
executed	O
.	O
</s>
<s>
The	O
string	O
to	O
replace	O
may	O
appear	O
multiple	O
times	O
in	O
the	O
command	B-Application
part	O
.	O
</s>
<s>
Another	O
way	O
to	O
achieve	O
a	O
similar	O
effect	O
is	O
to	O
use	O
a	O
shell	O
as	O
the	O
launched	O
command	B-Application
,	O
and	O
deal	O
with	O
the	O
complexity	O
in	O
that	O
shell	O
,	O
for	O
example	O
:	O
</s>
<s>
Many	O
Unix	B-Application
utilities	O
are	O
line-oriented	O
.	O
</s>
<s>
These	O
may	O
work	O
with	O
xargs	B-Application
as	O
long	O
as	O
the	O
lines	O
do	O
not	O
contain	O
'	O
,	O
"	O
,	O
or	O
a	O
space	O
.	O
</s>
<s>
Some	O
of	O
the	O
Unix	B-Application
utilities	O
can	O
use	O
NUL	O
as	O
record	O
separator	O
(	O
e.g.	O
</s>
<s>
Perl	B-Language
(	O
requires	O
-0	O
and	O
\0	O
instead	O
of	O
\n	O
)	O
,	O
locate	B-Application
(	O
requires	O
using	O
-0	O
)	O
,	O
find	B-Application
(	O
requires	O
using	O
-print0	O
)	O
,	O
grep	B-Application
(	O
requires	O
-z	O
or	O
-Z	O
)	O
,	O
sort	B-Application
(	O
requires	O
using	O
-z	O
)	O
)	O
.	O
</s>
<s>
Using	O
-0	O
for	O
xargs	B-Application
deals	O
with	O
the	O
problem	O
,	O
but	O
many	O
Unix	B-Application
utilities	O
cannot	O
use	O
NUL	O
as	O
separator	O
(	O
e.g.	O
</s>
<s>
head	B-Device
,	O
tail	B-Application
,	O
ls	B-Application
,	O
echo	B-Application
,	O
sed	B-Application
,	O
tar	B-Application
-v	O
,	O
wc	B-Application
,	O
which	B-Device
)	O
.	O
</s>
<s>
But	O
often	O
people	O
forget	O
this	O
and	O
assume	O
xargs	B-Application
is	O
also	O
line-oriented	O
,	O
which	B-Device
is	O
not	O
the	O
case	O
(	O
per	O
default	O
xargs	B-Application
separates	O
on	O
newlines	O
and	O
blanks	O
within	O
lines	O
,	O
substrings	O
with	O
blanks	O
must	O
be	O
single	O
-	O
or	O
double-quoted	O
)	O
.	O
</s>
<s>
The	O
proper	O
fix	O
is	O
to	O
use	O
the	O
GNU-specific	O
-print0	O
option	O
,	O
but	O
tail	B-Application
(	O
and	O
other	O
tools	O
)	O
do	O
not	O
support	O
NUL-terminated	O
strings	O
:	O
</s>
<s>
This	O
is	O
equivalent	O
to	O
the	O
more	O
verbose	O
command	B-Application
:	O
or	O
shorter	O
,	O
by	O
switching	O
xargs	B-Application
to	O
(	O
non-POSIX	O
)	O
line-oriented	O
mode	O
with	O
the	O
-d	O
(	O
delimiter	O
)	O
option	O
:	O
</s>
<s>
GNU	B-Application
parallel	I-Application
is	O
an	O
alternative	O
to	O
xargs	B-Application
that	O
is	O
designed	O
to	O
have	O
the	O
same	O
options	O
,	O
but	O
is	O
line-oriented	O
.	O
</s>
<s>
Thus	O
,	O
using	O
GNU	B-Application
Parallel	I-Application
instead	O
,	O
the	O
above	O
would	O
work	O
as	O
expected	O
.	O
</s>
<s>
For	O
Unix	B-Application
environments	O
where	O
xargs	B-Application
does	O
not	O
support	O
the	O
-0	O
nor	O
the	O
option	O
(	O
e.g.	O
</s>
<s>
Alternatively	O
,	O
one	O
can	O
avoid	O
using	O
xargs	B-Application
at	O
all	O
,	O
either	O
by	O
using	O
GNU	B-Application
parallel	I-Application
or	O
using	O
the	O
functionality	O
of	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
diff	O
command	B-Application
operates	O
on	O
two	O
files	O
at	O
a	O
time	O
.	O
</s>
<s>
The	O
-n	O
option	O
to	O
xargs	B-Application
specifies	O
how	O
many	O
arguments	O
at	O
a	O
time	O
to	O
supply	O
to	O
the	O
given	O
command	B-Application
.	O
</s>
<s>
The	O
command	B-Application
will	O
be	O
invoked	O
repeatedly	O
until	O
all	O
input	O
is	O
exhausted	O
.	O
</s>
<s>
Use	O
xargs	B-Application
to	O
break	O
up	O
the	O
input	O
into	O
two	O
arguments	O
per	O
line	O
:	O
</s>
<s>
In	O
addition	O
to	O
running	O
based	O
on	O
a	O
specified	O
number	O
of	O
arguments	O
at	O
a	O
time	O
,	O
one	O
can	O
also	O
invoke	O
a	O
command	B-Application
for	O
each	O
line	O
of	O
input	O
with	O
the	O
-L	O
1	O
option	O
.	O
</s>
<s>
The	O
argument	O
separator	O
processing	O
of	O
xargs	B-Application
is	O
not	O
the	O
only	O
problem	O
with	O
using	O
the	O
xargs	B-Application
program	O
in	O
its	O
default	O
mode	O
.	O
</s>
<s>
Most	O
Unix	B-Application
tools	O
which	B-Device
are	O
often	O
used	O
to	O
manipulate	O
filenames	O
(	O
for	O
example	O
sed	B-Application
,	O
basename	O
,	O
sort	B-Application
,	O
etc	O
.	O
)	O
</s>
<s>
However	O
,	O
Unix	B-Application
path	O
names	O
are	O
not	O
really	O
text	O
.	O
</s>
<s>
As	O
a	O
result	O
,	O
an	O
absolute	O
path	O
name	O
in	O
a	O
Unix	B-Application
system	I-Application
may	O
not	O
be	O
correctly	O
processable	O
as	O
text	O
under	O
a	O
single	O
character	O
encoding	O
.	O
</s>
<s>
Tools	O
which	B-Device
rely	O
on	O
their	O
input	O
being	O
text	O
may	O
fail	O
on	O
such	O
strings	O
.	O
</s>
<s>
One	O
workaround	O
for	O
this	O
problem	O
is	O
to	O
run	O
such	O
tools	O
in	O
the	O
C	O
locale	O
,	O
which	B-Device
essentially	O
processes	O
the	O
bytes	O
of	O
the	O
input	O
as-is	O
.	O
</s>
