11

I created a directory called folder and took away execute permission.

$ mkdir folder
$ touch folder/innerFile
$ mkdir folder/innerFolder
$ chmod -x folder

Now if I do

$ ls folder

it outputs a list of files, but when I do

$ ls -l folder

I get

ls: innerFile: Permission denied
ls: innerFolder: Permission denied

Why is that?

  • 4
    Check this answer. It has answers to your question. – Ramesh Nov 3 '14 at 1:12
  • 2
    "What is the difference between 'ls' and 'ls -l' when I don't have execute permission on that directory?" Basically, it's the same as the difference between 'ls' and 'ls -l' when you do have execute permission on the directory. – G-Man Says 'Reinstate Monica' Nov 3 '14 at 22:52
18

ls -l on a folder tries to stat its contents, whereas ls doesn't:

$ strace ls folder -l
...
lstat("folder/innerFolder", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
getxattr("folder/innerFolder", "system.posix_acl_access", 0x0, 0) = -1 ENODATA (No data available)
getxattr("folder/innerFolder", "system.posix_acl_default", 0x0, 0) = -1 ENODATA (No data available)
lstat("folder/innerFile", {st_mode=S_IFDIR|0755, st_size=40, ...}) = 0
getxattr("folder/innerFile", "system.posix_acl_access", 0x0, 0) = -1 ENODATA (No data available)
getxattr("folder/innerFile", "system.posix_acl_default", 0x0, 0) = -1 ENODATA (No data available)
...

That's why you get a "permission denied" with ls -l and not with ls.

| improve this answer | |

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.