Handle Too-Long Command Lines with xargs

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 If your system doesn't already have xargs, be sure to install it from the tutorial.

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 the next article () explains, xargs can have trouble if an argument has white space inside a word. Luckily, the GNU xargs (read about it there) solves the problem.

- JP