Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm fairly new to Unix and I have written a script:

SERVER="/usr/local/abc/.../somefile.txt"
OPTION="$1"

if [ x$OPTION = "xtitle" ]
then
        grep $OPTION $SERVER
        exit
fi

As far as I understand, when I call the script with arg "title" as ".../script title" it should return what line grep found in that file consisting string "title". I've placed 0777 permissions on the script (I know that's an overkill, but security isn't important right now). I've also put 0777 permissions on somefile.txt. I put this script to run as a part of another program, it has it's own user. But in the logs of this other program I keep seeing :

grep: /usr/local/abc/..../somefile.txt: Permission denied

Is it possible that something can't be accessed even if it has 777 permissions? Is it possible that another user just can't see that folder?

share|improve this question
    
can you please paste the output of ls -l <your script> <somefile.txt>...... –  raghav mishra Feb 19 '13 at 8:02
    
The permissions on the script are irrelevant. And don't get into the habit of using 777 permissions. In fact, forget about numeric permissions. If you want to make a file readable by all, use chmod a+r. –  Gilles Feb 19 '13 at 9:57

1 Answer 1

up vote 4 down vote accepted

As you already suggested, if the user can not see the folder containing the file, s/he won't be able to access the file.

In order to access the file, the folder needs to have read and execute bits set for the current user or group s/he is part of or for all others.

share|improve this answer
    
But I've put 0777 permissions, isn't that full permissions for everyone? –  Iļja Gubins Feb 19 '13 at 8:54
2  
@the_lay no, you also have to have access to the intermediate folders, so in other words for your user you have to have at least the execute bit set for each of folders –  Ulrich Dangel Feb 19 '13 at 9:26
1  
Both bbaja42 and Ulrich are right. On Windows with NTFS it would be the same, you need to have the rights on the complete directory tree up to the file. It is like you have a chest in a room and someone gave you the key of the chest. If the room is locked and you don't have the key, you can not open the chest, although in theory someone gave you the permission! –  Huygens Feb 19 '13 at 9:49
    
Thank you everyone! I didn't realise that I must set access to intermediate folders. –  Iļja Gubins Feb 19 '13 at 10:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.