How to use individual lines pulled from stdin in the middle of a command when using xargs

xargs is very powerful commandline utility. Here is what Wikipedia says about xargs

xargs is a command on Unix and most Unix-like operating systems used to build and execute command lines from standard input

Most common use of xargs would be to do something like,

find . -type f -print0 | xargs -0 rm

Let us assume that you have a file with list of files to be downloaded from a website. Something like,

With wget and xargs all these files can be downloaded easily with just one command.

cat filenames.txt | xargs -I filename wget

-I flag takes a replacement string and xargs will then replace filename with the value obtained from stdin.

comments powered by Disqus