PDA

View Full Version : [SOLVED] Why does a folder need execute permission?



froggyswamp
October 12th, 2009, 12:29 AM
Folks I noticed that despite having read/write access to a folder (inside home dir, which contains simple non-executable files) I can't read its content (files) until I also set the execute flag.
I'm surprised, anyone knows what's the reason?

peetbull
October 12th, 2009, 02:34 AM
This is indeed a confusing part of directory privileges.

As I get it:


write: create or delete files
execute: access files

Maybe a real-life-ish example could give you the idea. Warning: it might sound odd, but it sustains the analogy.

Consider a real carton box (directory) in which we can add/remove any piece of paper (file) we want.


read: browsing the papers
write: adding/removing papers
execute: touching the box (to open it, or move it)

A more detailed guide about file permissions can be found here:
http://www.albany.edu/faculty/gms/homepage101/unix_permissions.html

Be well!

sgosnell
October 12th, 2009, 04:47 AM
You shouln't need to set the execute bit on a folder. I don't know what's wrong, but something is if you have to set that. If you're the owner, you can access the files unless something is wonky.

GuyCorngood
October 12th, 2009, 06:15 AM
From Wikipedia (http://en.wikipedia.org/wiki/File_system_permissions):


The execute permission, which grants the ability to execute a file. This permission must be set for executable binaries (for example, a compiled c++ program) or shell scripts (for example, a Perl program) in order to allow the operating system to run them. When set for a directory, this permission grants the ability to traverse its tree in order to access files or subdirectories, but not see files inside the directory (unless read is set).

So:


% pwd
/home/mark/tmp
% ls -l
total 8
dr--r--r-- 2 mark users 4096 2009-10-12 01:03 r
dr-xr-xr-x 2 mark users 4096 2009-10-12 01:03 rx
% cd r
cd: permission denied: r
% cd rx
% pwd
/home/mark/tmp/rx
% cd ..
% ls r
ls: cannot access r/file: Permission denied
ls: cannot access r/dir: Permission denied
dir file
% ls rx
otherdir otherfile
% cd r/dir
cd: permission denied: r/dir
% cd rx/otherdir
% pwd
/home/mark/tmp/rx/otherdir

Mister.Vash
October 12th, 2009, 06:16 AM
You shouln't need to set the execute bit on a folder. I don't know what's wrong, but something is if you have to set that. If you're the owner, you can access the files unless something is wonky.

If you have drives are setup normally, then you do to have that set. Permissions are different when mounting windows file systems, but that wasn't what was being asked about.

If everything is setup normally, in your home folder for example, and you create a test folder with a file in it then chmod 600 to the new folder to get rid of the execution bit, you would no longer be able to see the file that you put in it. Go ahead and try if you like, you should be able to access that folder under normal conditions.

Here are some additional details on it
http://content.hccfl.edu/pollock/AUnix1/FilePermissions.htm

It's best to think of them as two different bits - the execution bit on a file means you can execute that program - the execution bit on a directory basically allows the contents of the directory to bee seen. So with that bit, you can't see the contents of the folder.

wmcbrine
October 12th, 2009, 10:40 AM
On a directory, setting the executable bit allows you to change to or use that directory (not to read it). A directory without the executable bit set isn't useful, but a directory with the executable bit set, but the read bit not set can be. You can change to such a directory, but not list it. You can still read and write files in this directory if you know their names, even though you can't list them.

Edit: Or, in other words, what #4 said.

froggyswamp
October 12th, 2009, 11:27 AM
Thanks everybody!! if I wasn't that greedy I'd buy you a beer :)