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?

Shnd
  • 577
  • 1
  • 5
  • 9
  • 4
    Check [this](http://unix.stackexchange.com/a/21263/47538) answer. It has answers to your question. – Ramesh Nov 03 '14 at 01: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 03 '14 at 22:52

1 Answers1

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.

muru
  • 69,900
  • 13
  • 192
  • 292