while [ -f /tmp/restarting_server ] ; do {
[ $((i=i+1)) -ge 10 ] && exit 1
sleep 1
} ; done
You dont need find
if you know already the exact filename, pathname, and conditions under which a file should be acceptably found.
So the other problem - exiting your script from your -exec
statement - is maybe not the problem you consider it to be. find
doesn't build in an option for kill
ing its parent shell because the shell already provides it.
find … -exec sh -c kill\ $$ \;
Consider also that you can use this construct for signalling based on existing paths even if you're not certain before hand where they'll be:
trap 'stuff to do' USR1
… #later…
find … -exec sh -c kill\ -USR1\ $$ \;
And this opens a lot of other options to you as well:
find … -exec sh -c exec…
EDIT:
I've just thought of other options involving parameter expansion
to make your shell exit without find
's -exec
at all that could be used in other ways:
hold_file="$(find . -name file)"
${hold_file:+false} : || exit 1
or
N= ; hold_file="$(find . -name file)"
${hold_file:+${N:?lock file remains, exiting...}}
Both of these will only cause an exit if the variable to which you assign find
's stdout
is neither null
or unset. And of course, should you desire to fail based on an empty find, you can do the same with :-
instead of :+
and omitting the $N
ull value variable entirely.
Or just to alter find
's exit status:
$(find . -name file -exec echo false \; ) : || exit 1
You can do:
find . -exec ./is_dir.py {} \; -o -print
It will list everything that is not a directory. Assuming that is_dir.py
is executable (chmod +x is_dir.py
) and contains something like:
#!/usr/bin/env python
import sys
import os
if os.path.isdir(sys.argv[1]):
sys.exit(0)
sys.exit(1)
And if is_dir.py
generates output of its own, you can do:
rm -f nondir.lst
find . -exec ./is_dir.py {} \; -o -exec echo {} >> nondir.lst \;
so that its outoput doesn't get mixed with the list of names for which is_dir.py
fails.
Best Answer
Not really, you can integrate the ls command with find,
find Test/ -type f -perm /u=x,g=x,o=x -exec ls -l {} \;
UPDATE
Actually
-executable
is not an equivalent of-perm /u=x,g=x,o=x
. You might have files that is executable only by the group or others, which will not be displayed.So, depends on your purpose, if you want files executable only by you, that's okay to use
-executable
.