1

When I run the find command with an -exec subcommand that fails, find returns a 0 exit code:

$ find . -iname '*.txt' -exec ls foo \;
ls: foo: No such file or directory
ls: foo: No such file or directory
ls: foo: No such file or directory
ls: foo: No such file or directory
ls: foo: No such file or directory
ls: foo: No such file or directory
ls: foo: No such file or directory
$ echo $?
0

Is there any way to make find fail if any of its subcommands fail?

David Eyk
  • 667
  • 1
  • 7
  • 18

1 Answers1

0

That's the limitation of find. Refer to the standard: http://pubs.opengroup.org/onlinepubs/009695399/utilities/find.html

It will return 0 unless error happened while traversing directories.

Use xargs instead.