Checking directory permissions on UNIX directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking directory permissions on UNIX directory
# 1  
Old 07-21-2011
Checking directory permissions on UNIX directory

Hi,

How do i check if I have read/write/execute rights on a UNIX directory?

What I'm doing is checking read access on the files but i also want to check if user has rights on the direcory in whcih these files are present.

Code:
if [ ! -r ${filename} ] then......

And I check if the directory exists by using this command

Code:
if [ ! -d "${dest}" ] then...

Can anyone tell me how do i check if the user has read/write/execute rights on a UNIX directory ?

Last edited by pludi; 07-21-2011 at 05:56 AM..
# 2  
Old 07-21-2011
As well as for regular files.
This User Gave Thanks to yazu For This Post:
# 3  
Old 07-21-2011
Ok, so if i need to check for all r w x rights can I do it in 1 command line?

if [ ! -rwx ${directory} ] ?

This gives an unary operator expected error. I believe we need to have an and operator ??
# 4  
Old 07-21-2011
Shell is not perl (in the last version of perl you can use these operators in such manner - "-rwx" ). In shell you can use:

Code:
if [ ! -r $dir ] && [ ! -w $dir ] && [ ! -x $dir ]
...

Or
Code:
$ dir=$HOME
$ test -r $dir -a -w $dir -a -x $dir && echo hi
hi
$ dir=/etc
$ test -r $dir -a -w $dir -a -x $dir && echo hi
$


Last edited by yazu; 07-21-2011 at 06:54 AM.. Reason: another variant
# 5  
Old 07-21-2011
Ohk so here in the shell script i have to check the permissions separately like I have done below.

if [ ! -r ${source} ]
then
echo "Read access permission denied on Source Directory"
exit 1
fi
if [ ! -w ${source} ]
then
echo "Write access permission denied on Source Directory"
exit 1
fi
if [ ! -x ${source} ]
then
echo "Execute access permission denied on Source Directory"
exit 1
fi


kindly let me know if this is the ideal way to check rwx rights or is there any better way to do this...!!
# 6  
Old 07-21-2011
Sorry, I think I was ambiguous. I edited my previous post.
# 7  
Old 07-21-2011
Thanks again Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extract directory name from the full directory path in UNIX using shell scripting

My input is as below : /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/loyal/IFIND.HELLO.WROC.txt /splunk/scrubbed/triumph/ifind.triumph.txt From the above input I want to extract the file names only . Basically I want to... (5 Replies)
Discussion started by: IshuGupta
5 Replies

2. UNIX for Dummies Questions & Answers

Directory (and sub-directory) permissions...

Hi, I had a newbie question on giving permissions to directories and subdirectories. I am one of the users in a group. The top level directory (say directory 'X' - owned by someone else) has the following permissions: drwxrwxrwx It also has a subdirectory, say 'Y', (which in turn has... (5 Replies)
Discussion started by: pc2001
5 Replies

3. Solaris

Directory Permissions for 2 users on 1 directory

we want to allow user to FTP files into a directory, and then the program (PLSQL) will read and process the file, and then move the file to other directory for archiving. the user id: uftp1, group: ftp the program run in oracle database, thus have the user Id: oraprod, group: dba how to... (2 Replies)
Discussion started by: siakhooi
2 Replies

4. Shell Programming and Scripting

File transfer from one directory to another directory in unix

Hi, I have to transfer five files from one directory to another directory in unix with the help of shell scripts. This shell script calling the param file as input parameter. Every day one file will come and fall on my source directory. Remaining files will fall on any one of the day of the... (5 Replies)
Discussion started by: easterraj
5 Replies

5. Shell Programming and Scripting

Move a file from windows directory to unix directory

Move a file from windows directory to unix directory, is this possible? if it is, can someone help me on this? Thanks! God bless! (1 Reply)
Discussion started by: kingpeejay
1 Replies

6. UNIX for Dummies Questions & Answers

unix directory permissions

Hi All I am using cygwin and if i type ls -l it is giving like drwxr-xr-x+ for directories. My question is what is the meaning of '+' sign at the end? its not giving that '+' sign for files. Thank you (1 Reply)
Discussion started by: Usha Shastri
1 Replies

7. Shell Programming and Scripting

determine owner directory permissions from within the directory

From within a directory, how do I determine whether I have write permission for it. test -w pwd ; echo ? This doesn't work as it returns false, even though I have write permission. (4 Replies)
Discussion started by: Sniper Pixie
4 Replies

8. Shell Programming and Scripting

Checking and chaning directory permissions automatically

Hi all, My first post here. I need a small script to check the directory permssions on my /home/uploads and if there are any newly created directory in uploads chmod them to 1777. The upload directory is for my users who upload their pictures and I by default their directories are given... (4 Replies)
Discussion started by: apachi
4 Replies

9. UNIX for Dummies Questions & Answers

moving files from a unix directory to a windows directory

Any body any ideas i'm failry new to this so any help would be appreciated. Cheers Steve (2 Replies)
Discussion started by: gleads
2 Replies

10. UNIX for Advanced & Expert Users

Unix directory permissions for Samba

Hi, I've installed Samba on an AIX machine and configured smb.conf to have a bunch of shares available to Windows. I can see the shares, but I couldn't access them. After about 30 minutes of chmod'ding if finally got access by doing the following to the directories I shared: chmod -R... (2 Replies)
Discussion started by: szahir1
2 Replies
Login or Register to Ask a Question