Power of find and xargs
Doesn’t, the unix commands find, xargs and grep look like map, apply and filter of the functional world? I was looking at the OCW website and downloaded some content from there as a zip file, which had a complicated directory structure. I wanted to flatten the directory structure, so that all the pdfs are in one directory. With find and xargs it turned out to be extremely easy.
$ find ./ -name *.pdf -print | xargs -I xxx cp xxx /tmp
The key is the -I argument to xargs which replaces every occurance of the pattern in the command with the input from stdin.
Also don’t the pipes look like calling a function composition like in f(g(x) as mentioned by this post?
Syndicated 2010-03-17 07:00:00 from Ramakrishnan Muthukrishnan