Why does "ls" sporadically output only "." in the root directory of an external drive?

It may be a bug in the filesystem driver for FAT32 on recent versions of OSX. This also only appears to occur when the working directory is at the root of the mounted drive. If it's in a subdirectory or anywhere else on the system things seem to work.

There's some interesting discussion in this thread including system traces. https://github.com/robbyrussell/oh-my-zsh/issues/4161


WORKAROUND: (probably part of what the asker would appreciate even if they didn't specifically ask for it)

Refer to the current directory in almost any way other than .. Example:

cd to a subdirectory, and then run ls on the parent directory. That is, enter something like this:

mkdir S; cd S ; /bin/ls -al ..

Or refer to it by it's full pathname. Example:

ls /Volumes/microSD007

For me, either of these workarounds work (that is, they result in the expected output) when ls gives me the same wrong output the OP reported. (And for me, there's no output in dmesg when ls acts oddly.)

I'm seeing the same malfunctions on 10.12.6 in Terminal.app running bash. Same in csh and sh, even after setting TERM to vt100. This workaround works in those shells too.

And I agree there's a bug in stat64, as indicated in the zsh issue thread Neil points us to. (I had thought the issue was caused by flawed and/or fake flash memory, and still wonder if that's a factor sometimes.)

I noticed that this bug also affects:

  • Emacs' dired mode, because it calls ls, and
  • ls when it's used in Emacs' shell mode.

Tags:

Ls

Usb Drive

Osx