{"id":2290,"date":"2017-12-08T06:35:01","date_gmt":"2017-12-08T06:35:01","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=2290"},"modified":"2020-01-09T09:50:06","modified_gmt":"2020-01-09T09:50:06","slug":"find-command-return-type","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/find-command-return-type\/","title":{"rendered":"Find command return type"},"content":{"rendered":"<p><strong>scmuser created the topic: Find command return type<\/strong><br \/>\nI am looking for following answer if anybody can help me out&#8230;<\/p>\n<p>How to Return a message when a file is not found using find command? OR<br \/>\nFind command return type OR<br \/>\nwhen the file is not found i want it to return some value OR<\/p>\n<p><strong>tpatil replied the topic: Re: Find command return type<\/strong><br \/>\nYou can use exit code of find command to return the message.<\/p>\n<p>e..g.<\/p>\n<p><code>find . -name abc.txt > dev\/null<\/p>\n<p>if test $? -eq 0<br \/>\nthen<br \/>\n   echo \"File found\"<br \/>\nelse<br \/>\n   echo \"File Not Found\"<br \/>\nfi<\/code><\/p>\n<p>Hope this helps&#8230;<\/p>\n<p><strong>rajeshkumar replied the topic: Re: Find command return type<\/strong><br \/>\nHi..<\/p>\n<p>I guess following script will not work. The problem here is find command does always return true value no matter if find is available or not.<\/p>\n<p>this is unique things in find command.<\/p>\n<p>I feel we should go ahead in this way.<\/p>\n<p><code>find . -name raj.txt > raj.txt<br \/>\ncounter= `cat abc.txt | wc -l'<\/p>\n<p>if [$counter -gt 0]<br \/>\nthen<br \/>\n\techo \"File is found\"<br \/>\nelse<br \/>\n\techo \"File is not found\"<br \/>\nfi<\/code><\/p>\n<p>please let us your inputs on this<br \/>\nRegards,<br \/>\nRajesh Kumar<br \/>\nTwitt me @ <a href=\"http:\/\/twitter.com\/RajeshKumarIn\" target=\"_blank\" rel=\"noopener\">twitter.com\/RajeshKumarIn<\/a><\/p>\n<p><strong>tpatil replied the topic: Re: Find command return type<\/strong><br \/>\nThanks Rajesh&#8230;You are right. I tried with my code. Find always retuns 0 though file not found.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>scmuser created the topic: Find command return type I am looking for following answer if anybody can help me out&#8230; How to Return a message when a file is not&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[454],"tags":[333],"class_list":["post-2290","post","type-post","status-publish","format-standard","hentry","category-shell-script","tag-command"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=2290"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2290\/revisions"}],"predecessor-version":[{"id":2291,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2290\/revisions\/2291"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=2290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=2290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=2290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}