Solved

Using Find command to verify a directory and file exist

Posted on 2004-10-13
3
709 Views
Last Modified: 2010-04-21
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
Comment
Question by:elwayisgod
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
yuzh earned 250 total points
ID: 12305572

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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 12312130
find . -name file -a -perm 666 | grep '^\./dir/'
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 12312134
oops, you need to adapt permission 666 to your needs
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question