Multiple arguments xargs example on downloading files with each given name?

Viewed 45

To save with a relative given name I normally do

wget -q -O tux.png https://git.kernel.org/cgit-data/cgit.png

With lines made by name and path, how to use xargs for downloading files?

~ cat list
tux.png https://git.kernel.org/cgit-data/cgit.png
pallo.png https://cgit.freebsd.org/freebsd.png
2 Answers

This kind of issue happened to me recently. I think of two ways

  1. xargs sh -c
# $a is the local file name, cut out from url, 
# $arg is the urls
cat ~/l | xargs -d $'\n' sh -c 'for arg do  a=$(echo "$arg"|cut -d '.' -f 7);echo $a "$arg" | wget --output-document $a "$arg";done'
  1. sh
cat l | awk -F '.' '{print "wget -q  -O " "~/" $4 $0}' | sh

By considering a input list, made by name and path each line, here is how to download files with multiple arguments xargs

BSD MacOS

xargs < list -L1 bash -c 'wget -q -O $0 $1'

GNU Linux

xargs < list -l bash -c 'wget -q -O $0 $1'

for parallel mode use option -P e.g.

xargs < list -P 24 -L1 bash -c 'wget -q -O $0 $1'
Related