2.2. Xargs

When using the -exec option in find to process files, find passes all the located files to exec to be worked on in one go. Unfortunately on some systems there is only a limited command line length that can be passed to exec before it bombs out after running for a few minutes with an error message. The error message usually says ‘Too long on Args list’ or ‘Args list exceeded’. This is where xargs comes in, especially when using find. Find passes on the located files to xargs and xargs grabs the files in portions and not all in one go, unlike using exec. Thus it can process the first portion of files, do its stuff, then request the next batch of the files and so on.

Let’s see how xargs fits in with some find examples.

The following ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.