Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 724
  • Last Modified:

Using Find command to verify a directory and file exist

How can I use find to verify a directory exists and that a particular file in that directory is present and is r-w ?

Thanks,
0
elwayisgod
Asked:
elwayisgod
  • 2
1 Solution
 
yuzhCommented:

DIR=`find / -type d -name "dirname" `

if [ -z $DIR ]  ; then
     echo "dirname doesn't exist !"
else
     if [ `find $DIR -type f -name "myfile" -perm a=rw ` ] ; then
        echo "myfile is rw!"
     else
        echo "myfile doesn't exist or doesn't have rw permission"
     fi
fi


man find
to learn more details, pay attention to "perm"
0
 
ahoffmannCommented:
find . -name file -a -perm 666 | grep '^\./dir/'
0
 
ahoffmannCommented:
oops, you need to adapt permission 666 to your needs
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now