0

What is the situation why ls -l returns a list of subdirectories in the form below?

 d????????? ? ? ? ?       ? Subdirectory

A tree launched on that directory returns 0 directories, 0 files for example. The system seems to know the name of the subdirectory but cannot find it.
Which missing link confuses ls?

Late note. On directories, thus not on files, see also:

XavierStuvw
  • 1,119
  • 1
    https://serverfault.com/a/217676/692743 – zjeffer Oct 29 '21 at 21:45
  • 1
    https://unix.stackexchange.com/q/393598/170373 https://unix.stackexchange.com/q/542422/170373 https://unix.stackexchange.com/q/158443/170373 – ilkkachu Oct 31 '21 at 23:03
  • re. that late note, I'm not sure what you mean with "thus not files". If the user doesn't have x access to the directory, they can't read the permission bits of the contained entries, regardless of if those entries are files or directories. On some systems, they can get the type though, so ls can show d?????????, or -?????????. The answers in that linked question mention the same permissions issue that's also mentioned in the answer below. – ilkkachu Nov 01 '21 at 10:53

1 Answers1

5

You have read, but not execute/search permissions to the containing directory.

Easy to reproduce with:

mkdir -p foo/bar; chmod -x foo; ls -l foo
ls: cannot access 'foo/bar': Permission denied
total 0
d????????? ? ? ? ?            ? bar

On Linux and BSD, ls is able to get that it's a directory from the d_type field of the directory entry, but not much more.

That may also happen in other situations where ls is not able to access the actual inode, but only the directory entry which points to it (as when the file or directory inode has disappeared before ls was able to stat() it -- see this, or when the it's an inaccessible mount point -- see this).