Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Permission for files:

chmod 664 myFile // rw-rw-r--

And for folders:

chmod 774 myFolder // rwxrwxr--

If I only use the "read and write" permission, the folders won't show its contents, why ?

share|improve this question

migrated from stackoverflow.com Jul 28 '10 at 0:21

This question came from our site for professional and enthusiast programmers.

6 Answers 6

up vote 19 down vote accepted

Directories (they're not typically called folders in *nix) have different meaning for the permission bits than normal files.

For directories, write allows creating new files inside of it.

Read allows you to list the files inside of it.

Execute allows you to enter it and access files (or other directories) inside.

share|improve this answer
    
An easy way to remember is to imagine executing as a double-click on something. When you double-click the directory (or cd) you enter(execute) it. –  John T Jul 30 '10 at 14:27

Since you can't 'execute' a directory, the execute bit has been put to better use. The execute bit on a directory allows you to access items that are inside the directory, even if you cannot list the directories contents.

$ mkdir -p dir/
$ echo 'Hello World!' > dir/file
$ chmod 000 dir/
$ ls -al dir/
ls: cannot open directory dir: Permission denied
$ cat dir/file
cat: dir/file: Permission denied
$ chmod +x dir/
$ ls -al dir/
ls: cannot open directory dir: Permission denied
$ cat dir/file
Hello World!

From the chmod manpage:

The letters rwxXst select file mode bits for the affected users: read (r), write (w), execute (or search for directories) (x), execute/search only if the file is a directory or already has execute permission for some user (X), set user or group ID on execution (s), restricted deletion flag or sticky bit (t).

share|improve this answer

The x bit on a folder refers to indexing/directory search/listing; none of those are possible if you keep that bit low.

Here's an example of its use: If you want to have a user with limited read permissions on every directory but his home, say /home/dummy, then you need to make / and /home have the x bit set, otherwise he can't even get to his home directory.

share|improve this answer

The "execute" bit actually means "search" when applied to directories (from man chmod). This seems reasonable since execute has no meaning for a directory.

share|improve this answer

Execute permissions on a directory allow you to traverse it, for using resources contained within it.

share|improve this answer

When you ask the OS to open the folder, you are performing (i.e. executing) an operation on it.

share|improve this answer
1  
You could replace "folder" with "text file" in your answer and it would still be a true statement, but since text files don't require execute permissions, I don't see why your answer is relevant to the issue at hand. –  Rob Kennedy Jul 28 '10 at 0:20

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.