Skip to content

Instantly share code, notes, and snippets.

@ethagnawl
Last active December 1, 2017 01:25
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 ethagnawl/6af8d01e84aabcb16619b0c6d382b83a to your computer and use it in GitHub Desktop.
Save ethagnawl/6af8d01e84aabcb16619b0c6d382b83a to your computer and use it in GitHub Desktop.
dumb xargs demo
I've had a rough understanding of xargs for some time (allows you to do
_something_ with the output of a previous command), but never understood it
well enough to instinctively reach for it while working on the command line.
So, I decided I'd put a little demo together in order to learn more about it.
The demo is, admittedly, very basic but it was enough to help me get a better
understanding of what xargs can do and when you might want to use it.
Roughly, the demo does the following:
1.) pipe a list of images to xargs
2.) construct a URL for each image
3.) download files using newly constructed URLs - in parallel
1.jpg
2.jpg
3.jpg
4.jpg
5.jpg
6.jpg
7.jpg
8.jpg
9.jpg
10.jpg
#! /bin/bash
# 1.) pipe list of images to xargs
# 2.) construct URL for each image
# 3.) download files in parallel
cat images.txt | xargs -I img -P 0 wget -O img "http://fillmurray.com/222/"img
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment