Is there a way to write an find
so that it breaks if one of the -exec
operations fails on a file?
E.g. (javac
is conveniently used as a program that can return an exit code of 1 on some files and for no other reason):
$ echo "public classXX A{}" >> A.java
$ echo "public class B{}" >> B.java
$ find . -iname \*.java -exec javac {} \;
./A.java:1: error: class, interface, or enum expected
public classXX A{}
^
1 error
In the example above, although the exec
on the file A.java
failed (and returned an exit code of 1), the find
command proceeded and compiled file B.java
as well. Is there a way to break out of find
or should I use some form of for
instead?
My version of find:
$ find -version | head -1
find (GNU findutils) 4.4.2