determine whether 'find' cmd found the file or not
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Originally posted by theYinYeti As far as I know, find does not give an error status if no files are found. Depending on exactly what you want to do, I'm sure there's a better solutio, though.
AFAIK every command returns, or at least should, an error code on exit that can be used as a comparison operator (or as overlord73 stated, shown with $?). I tested those mini-scripts I posted above and they showed different results before and after touching the appropriate test file. I like the if [! -r file] (not readable) though, since I got that from a Slackware startup script
I'm not sure that looking to the error status would be a good strategy. What would it happen if find cannot access a directory? (for instance, if the user running the program has not permissions) It could happen that the file is found, but an error occuried.
I don't know exactly what "find" returns. Just wanted to point out that you should be careful.