Solved

Using Find command to verify a directory and file exist

Posted on 2004-10-13
3
710 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
ftpcommand 2 82
Problem logging tar errors 11 74
unix solaris snoop command 6 139
SCP a file to multiple machines using a script 4 94
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

751 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