[lug] A Windows user's view of linux
Sean Reifschneider
jafo at tummy.com
Tue Aug 5 15:35:34 MDT 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Jeffrey Haemer wrote:
> For me, this:
>
> find . -type f | xargs file
Good point.
That also has the benefit that it doesn't run one command for every
file like "-exec file '{}'" does. Which if you are doing hundreds of
thousands of files can be a huge load. However, be aware that if your
files are named strangely at all that the above will blow up:
guin:/tmp$ mkdir findtest
guin:/tmp$ touch findtest/'File With Spaces'
guin:/tmp$ find findtest -type f | xargs rm
rm: cannot remove `findtest/File': No such file or directory
rm: cannot remove `With': No such file or directory
rm: cannot remove `Spaces': No such file or directory
zsh: done find findtest -type f |
zsh: exit 123 xargs rm
guin:/tmp$ find findtest -type f -print0 | xargs -0 rm
guin:/tmp$
That said, newer finds include the "+" terminator which will do a similar
thing:
find findtest -type f -exec file '{}' +
You still have to quote the '{}', but not the +... This runs the command
with multiple arguments.
Note that in some cases you may want multiple arguments or single
arguments to influence output. For example, "grep" if given one argument
or stdin will report the matches, but if given multiple arguments will add
the file-name before the match. You can also influence that, in the case
of grep, with the -h and -H options.
I, personally, got in the habit of using xargs instead of -exec because of
the much fewer number of execs, but since finding out about the "+" suffix
I have gone back to using -exec and forgetting about -print0/xargs -0.
Sean
- --
Sean Reifschneider, Member of Technical Staff <jafo at tummy.com>
tummy.com, ltd. - Linux Consulting since 1995: Ask me about High Availability
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFImMemxUhyMYEjVX0RAt9LAKC93xRgB1O8y0b+t9gwWPtVRCtudwCfSpet
AKU12ajK1hI1uBh3T7NdtLo=
=26Zj
-----END PGP SIGNATURE-----
More information about the LUG
mailing list