Linux DevCenter    
 Published on Linux DevCenter (
 See this if you're having trouble printing code examples

Unix Power Tools
Handle Too-Long Command Lines with xargs

by Jerry Peek

xargs is one of those UNIX utilities that seems pretty useless when you first hear about it -- but turns into one of the handiest tools you can have.

xargs reads a group of arguments from its standard input, then runs a UNIX command with that group of arguments. It keeps reading arguments and running the command until it runs out of arguments. The shell's backquotes do the same kind of thing, but they give all the arguments to the command at once. This can give you a Too many arguments error.

Here are a couple of examples:

As tomorrow's article explains, xargs can have trouble if an argument has white space inside a word. Luckily, the GNU xargs solves the problem.

Back More Unix Power Tools


Copyright © 2009 O'Reilly Media, Inc.