scmuser created the topic: Find command return type
I am looking for following answer if anybody can help me out…
How to Return a message when a file is not found using find command? OR
Find command return type OR
when the file is not found i want it to return some value OR
tpatil replied the topic: Re: Find command return type
You can use exit code of find command to return the message.
e..g.
find . -name abc.txt > dev/null
if test $? -eq 0
then
echo "File found"
else
echo "File Not Found"
fi
Hope this helps…
rajeshkumar replied the topic: Re: Find command return type
Hi..
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.
this is unique things in find command.
I feel we should go ahead in this way.
find . -name raj.txt > raj.txt
counter= `cat abc.txt | wc -l'
if [$counter -gt 0]
then
echo "File is found"
else
echo "File is not found"
fi
please let us your inputs on this
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn
tpatil replied the topic: Re: Find command return type
Thanks Rajesh…You are right. I tried with my code. Find always retuns 0 though file not found.
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND