I'm trying to check the existence of several files, without knowing in advance where the files are located. So, I thought of find
as the de facto utility to do this... It works as expected, but the problem is that it does not acknowledge the non-existence of files, that is, if a file does not exists under the searched directory then, as you will expect, it's not showed in the results.
I guess this is fine, as the find
command is meant to find files, which actually exists in the first place (d'oh). But I wonder if there's a way for the find
command to return a message like "File not found" or alike, to inform that the file is not there, instead of failing (or succeeding) silently.
I thought that maybe I could workaround the problem by using find
's return code by querying $?
, but even when the file is not found the return code is 0
.
Just an example of what I have...
find . -name foo.sh
find . -name bar.sh
and what it returns in case the only file in there is foo.sh
:
./directory/foo.sh
What I would like to receive is:
./directory/foo.sh
bar.sh not found
Does anyone knows of a find
flag or any other workaround I can use?
Thanks!
you could try find . -name foo | grep \/
to set the exit code.
grep looks for any / in the output and returns exit code 1 if none is found
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments