Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check file permissions

Status
Not open for further replies.

scottpeter

Programmer
Sep 23, 2003
28
US
I need to check the permissions on a file or a directory. If I have read/write access I want to process that file/files in the directory.

Case I do not have either of these accesses, give a message that the file does not have required privileges and cannot be processed.

Can somebody please tell me how to do this in shell script.

Thanks,
Scott
 
man test
if [ -w /path/to/file]; then
# process that file
else
echo "the file does not have required privileges and cannot be processed"
fi

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

That was cool.

Just out of curiosity. How can I check for rw,rx or rwx permissions and print the same message.

Thanks,
Scott
 
Have you read the man page ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Oops, I missed the man test part.

However I checked the man page for test. It gives only for
r,w,x,d... etc.

It does not give help for rw/rx or rwx.

Thanks,
Scott
 
And what about -o and -a ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Sorry for being stupid and not reading the man properly.

I got it now.

Thanks,
Scott.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top