Skip to content

Instantly share code, notes, and snippets.

@crittelmeyer
Created December 31, 2015 01:46
Show Gist options
  • Save crittelmeyer/443aed71797d692a6c0e to your computer and use it in GitHub Desktop.
Save crittelmeyer/443aed71797d692a6c0e to your computer and use it in GitHub Desktop.
xargs cheatsheet

In general xargs is used like this

$ prog | xargs utility

where prog is expected to output one or more newline/space separated results. The trick is that xargs does not! nessarly call utility once for each result, instead it splits the result list into sublists and calls utility for every sublist. If you want to force xargs to call utility for every single result you will need to invoke it with xargs -L1.

Note that xargs promises you that the sublist sent to utility is shorter than ARG_MAX (this is how it avoids those dreaded Argument list to long errors). You can get the current value of ARG_MAX using getconf ARG_MAX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment