Solved

Using Find command to verify a directory and file exist

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Help stop mail server from sending spam. 27 117
llcommand 6 76
Error while installing rpm 1 63
cron job says it ran, no results 25 94
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now