I cd to a directory that has a large number of files, 40,948 to be exact. When I issue ls it takes a long time and before the command finally prints the results to the screen it tells me "ls: cannot access : No such file or directory" for a few files.

It's not the same file names every time. When I do ls -l some files have no posix permissions just "???????" preceding the file name.

I tried to chown -R the directory because I wanted to change the group and I get a mixture of "chown: cannot access" or "chown: changing ownership of" + ": No such file or directory" on even more files than when I use ls.

This highlighted for me that I don't even know if a directory in Linux has a table of contents, I thought that maybe the toc was corrupted. But the fact that the results are always different suggests otherwise.

Could this be a "nofile" issue in /etc/security/limits.conf ?

  • 1
    Is this on a local disk? Is NFS or SMB involved? – roaima Mar 6 '15 at 22:15
  • I had such "????" effects as well when I recently had a severe unrecoverable problem with my filesystem. (I hope in your case it's something less problematic, but I suggest to make backups in case you yet haven't any.) How do the "????" files behave if you try open them, vith an editor or an application appropriate for the file type? What does stat on such a file says? And what is the output (for those files) if you run the find command on that directory? – Janis Mar 6 '15 at 23:21
  • No, this can't have anything to do with file descriptor limits, since ls and chmod don't open individual files. It's probably a corrupted disk (if this is a local filesystem) or a network error (if this is a remote filesystem). You need to tell us what kind of filesystem this is, and whether the errors are consistent for ls. Do you have errors when you run /bin/ls (exactly that command)? Post the output of strace ls -l SOMEFILE for one of the problematic files. Does anything appear in the system logs when you run ls? – Gilles 'SO- stop being evil' Mar 7 '15 at 18:49
  • @roaima: It's a "local" disk. VMware Guest using a SCSI disk provided by a datastore backed by Fibre Channel SAN. ls doesn't give any errors other than the notices of "No such file" I believe BowlOfRed has the correct answer. I'll check for filesystem corruption during my next maintenance window though just to be sure. – xdaxdb Mar 9 '15 at 3:02

It sounds to me like it is in heavy use by other processes.

Gathering the information you see is not necessarily atomic. It might get a list of filenames, then go and look up the information on the file (either for a long listing or to color the output). If the file is deleted between those two actions, then you'll get output similar to what you describe.

| improve this answer | |
  • @xdaxdb: Make note of the names that get error messages -- say jabberwocky is one. Check whether jabberwocky shows up in your next ls. Try ls -l jabberwocky -- does it look normal? If the result is "no", then the above answer is probably correct -- the files in question are getting deleted (or possibly renamed) while ls is running. – G-Man Says 'Reinstate Monica' Mar 6 '15 at 23:53
  • @BowlOfRed: I think you are correct. The files are being deleted in between the "steps" ls takes when it displays the directory contents. It explains everything. The files are not there anymore. – xdaxdb Mar 9 '15 at 2:52

This long break results from sorting 40,000+ files in a directory before you get the ls output. Try ls -lU | more (unsorted) to get closer to the weird filenames. Another option is --show-control-chars.

| 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.