
Oliver Jones wrote:
[oliver] mobility:~/1$ find . -name "file*" -printf "'%f'\n" 'file 3' 'file 2' 'file 1'
Except that will fall over on filenames with spaces in them. You want to pipe `find ... -print0` to something, most of the time. (Usually xargs(1). That’s much faster than spawning one process for every single file, too, even for a pretty small number of files.)
xargs is only useful for feeding commands that accept multiple files as arguments and do the same thing to each file (eg cat). All xargs does is take a large set of filenames/lines on standard input and break them up into smaller chunks to execute on the command line of the specified command. On a small number of files/lines xargs is likely to only execute the target command once.
you can use "-n 1" to only do one file, and -istr to make it insert the file in instead of str, so you can do ls * | xargs -ixxx cp xxx /some/other/dir (if for some reason cp * /some/other/dir wasn't desirable). And combine xargs with -0 for extra delimiting goodness.