Find command return type

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.

Rajesh Kumar
Follow me
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x