You might want to chain calls to find (once, when you learned, that it is possible, which might be today). This is, of course, only possible as long as you stay in find. Once you pipe to xargs it's out of scope.
Small example, two files a.lst and b.lst:
cat a.lst
fuddel.sh
fiddel.sh
cat b.lst
fuddel.sh
No trick here - simply the fact that both contain "fuddel" but only one contains "fiddel".
Assume we didn't know that. We search a file which matches 2 conditions:
find -exec grep -q fuddel {} ";" -exec grep -q fiddel {} ";" -ls
192097 4 -rw-r--r-- 1 stefan stefan 20 Jun 27 17:05 ./a.lst
Well, maybe you know the syntax for grep or another program to pass both strings as condition, but that's not the point. Every program which can return true or false, given a file as argument, can be used here - grep was just a popular example.
And note, you may follow find -exec with other find commands, like -ls or -delete or something similar. Note, that delete not only does rm (removes files), but rmdir (removes directories) too.
Such a chain is read as an AND combination of commands, as long as not otherwise specified (namely with an -or
switch (and parens (which need masking))).
So you aren't leaving the find chain, which is a handy thing. I don't see any advantage in using -xargs, since you have to be careful in passing the files, which is something find doesn't need to do - it automatically handles passing each file as a single argument for you.
If you believe you need some masking for finds {} braces, feel free to visit my question which asks for evidence. My assertion is: You don't.
find … -exec … {} +
is OpenBSD, which only acquired this feature with version 5.1 released in 2012. All BSDs have had-print0
for several years, even OpenBSD (though it resisted that feature for a while too). Solaris, on the other hand, sticks to POSIX features, so you get-exec +
and no-print0
. – Gilles 'SO- stop being evil' Jun 27 '12 at 23:07-print0
is a pain and though you can arguexargs --delimiter "\n"
isn't equivalent, I've never once used the former after discovering the latter. – Sridhar Sarnobat Jul 28 '15 at 17:27-0
is more of a pain than--delimiter "\n"
. – jw013 Jul 28 '15 at 21:54-0
, GNUxargs
needs-r
to avoid running the command if there's no input. – Stéphane Chazelas Oct 11 '15 at 20:19| xargs -r0 cmd
is thatcmd
's stdin is affected (depending on thexargs
implementation, it's/dev/null
or the pipe. – Stéphane Chazelas Oct 11 '15 at 20:20