in reply to yargs -- xargs but handle spaces in filenames

I hear ya. It's frustrating.
Using find -exec has its problems.. If you'll calling a perl script for example, it could be pretty slow to do this:
find ./ -type f -iname "*whatever*" -exec perlscript '{}' \;

Imagine you're using a db too, opening that connection can be expensive.

xargs rawks..

The following is an example that tells xargs that the delimiter is not the posix standard space, but the newline..

Find all files named jpg/JPG larger than one meg, store that to a text file:

find ./ -type f -iname "*jpg" -size +1M > /tmp/found
Use xargs (version 4.4.0 +), tell it the delimiter is a newline, pass this to mogrify to reduce size of files..
xargs --delimiter=\\n --arg-file=/tmp/found mogrify -resize 800x600
  • Comment on Re: yargs -- xargs but handle spaces in filenames

Replies are listed 'Best First'.
Re^2: yargs -- xargs but handle spaces in filenames
by pingo (Hermit) on Jul 16, 2009 at 12:55 UTC
    Same thing, slightly more convoluted (and I'm not sure it works outside bash):

    xargs --delimiter=\\n --arg-file=<(find ./ -type f -iname "*jpg" -size + +1M) mogrify -resize 800x600
      leocharre pointed out that <() is overkill here, but it's very useful elsewhere, such as with diff:
      diff -u <( perl version1.pl 2>&1 ) <( perl version2.pl 2>&1 )
      find ./ -type f -iname "*jpg" -size +1M | xargs --delimiter=\\n mogrif +y -resize 800x600

      Edit by tye to replace PRE tags with CODE tags

        --exec is still my preference, though (looks a bit nicer, imho, and no risk of the argument list being too long in case you just pipe everything and the kitchen sink to it):

        find ./ -type f -iname "*jpg" -size +1M --exec mogrify -resize 800x600 + {} \;