Solved

Using Find command to verify a directory and file exist

Posted on 2004-10-13
3
706 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
  • 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

832 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