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


if [ x$OPTION = "xtitle" ]
        grep $OPTION $SERVER

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?

  • can you please paste the output of ls -l <your script> <somefile.txt>...... – P4cK3tHuNt3R 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 'SO- stop being evil' Feb 19 '13 at 9:57

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.

  • But I've put 0777 permissions, isn't that full permissions for everyone? – the-lay 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. – the-lay Feb 19 '13 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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