8 Jan 2011 rkrishnan   » (Journeyer)

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

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!