Skip to content

Instantly share code, notes, and snippets.

@hgfischer
Created January 11, 2018 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hgfischer/c9c6eb6edfd4fd4d70a4636301ada228 to your computer and use it in GitHub Desktop.
Save hgfischer/c9c6eb6edfd4fd4d70a4636301ada228 to your computer and use it in GitHub Desktop.
xargs instead of for loops

xargs

xargs is really powerful and sometimes allows some one-liners that are easier to write and read than bash loops

Example 1

Deleting many indices from an ElasticSearch cluster, one-by-one.

curl -s localhost:9200/_cat/indices?h=index | \
  grep 2017 | \
  sort | \
  xargs -t -L1 -n1 -I '{}' curl -X DELETE 'localhost:9200/{}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment