6

I'm using CentOS 7 and trying to list a directory's contents but can't. When I try to list the contents, I get the following output:

[entpnerd@myhost ~]$ ls -ali /data/sharedlogs/otherhost/
ls: cannot access /data/sharedlogs/otherhost/vcs: Not a directory
total 12
2361284 drwxr-xr-x 4 root root 4096 Sep 26 14:40 .
2359297 drwxr-xr-x 6 root root 4096 Apr 26 17:41 ..
2362573 drwxr-xr-x 2 root root 4096 Mar 22  2017 tkr
      ? d????????? ? ?    ?       ?            ? vcs

The output states that my directory, vcs, is "Not a directory", even though it should be, since this is where files have been previously logged. Additionally, the file permission bits are now all question marks, as is the owner, and (inexplicably) the inode ID.

How can I get the file system to recognize my directory as a directory again?

After trying everything that I've outlined below, the only path forward that I see is to ensure that the disk is backed up and run fsck (as suggested by this forum) or possibly just formatting the entire mount. Hopefully I find a simpler and less drastic solution.


Some things I have tried:

  1. sudo: I tried running sudo ls but no difference in output.
  2. rm: I tried removing vcs to put it back but no luck. I tried this both with sudo and without, but no luck either. Oddly enough, when I try sudo rm it states Is a directory. I also tried rm with both the -r and the -d switches, with no luck also. The output I get from the rm command attempts are:

    [entpnerd@myhost ~]$ rm /data/sharedlogs/otherhost/vcs
    rm: cannot remove ‘/data/sharedlogs/otherhost/vcs’: Not a directory
    [entpnerd@myhost ~]$ sudo rm /data/sharedlogs/otherhost/vcs
    rm: cannot remove ‘/data/sharedlogs/otherhost/vcs’: Is a directory
    [entpnerd@myhost ~]$ sudo rm -r /data/sharedlogs/otherhost/vcs
    rm: cannot remove ‘/data/sharedlogs/otherhost/vcs’: Is a directory
    [entpnerd@myhost ~]$ rm -r /data/sharedlogs/otherhost/vcs
    rm: cannot remove ‘/data/sharedlogs/otherhost/vcs’: Not a directory
    [entpnerd@myhost ~]$ rm -rd /data/sharedlogs/otherhost/vcs
    rm: cannot remove ‘/data/sharedlogs/otherhost/vcs’: Not a directory
    [entpnerd@myhost ~]$ sudo rm -rd /data/sharedlogs/otherhost/vcs
    rm: cannot remove ‘/data/sharedlogs/otherhost/vcs’: Is a directory
    
  3. inode ID: I tried removing by the inode (as suggested by this answer to a similar question), but I had no luck with that either, because as you can see from the output of the above ls command, the vcs directory has no inode ID.
  4. Non-ASCII characters: In the post, "How to Delete the Undeletable Directory", the directory had non-ASCII characters. This also is not the case as I saw from the xxd output:

    [entpnerd@myhost ~]$ ls -l /data/sharedlogs/otherhost/ | xxd
    ls: cannot access /data/sharedlogs/otherhost/vcs: Not a directory
    0000000: 746f 7461 6c20 340a 6472 7778 722d 7872  total 4.drwxr-xr
    ...
    0000040: 3f3f 3f3f 3f20 3f20 3f20 2020 203f 2020  ????? ? ?    ?  
    0000050: 2020 2020 203f 2020 2020 2020 2020 2020       ?          
    0000060: 2020 3f20 7663 730a                        ? vcs.
    
  5. lsattr: As suggested by the similar question, "Why can't I delete this file as root?", I tried using the lsattr command, but with no luck either:

    [entpnerd@myhost ~]$ lsattr /data/sharedlogs/otherhost/
    -------------e-- /data/sharedlogs/otherhost/tkr
    /data/sharedlogs/otherhost/vcs: Not a directory
    [entpnerd@myhost ~]$ lsattr /data/sharedlogs/otherhost/vcs
    lsattr: Not a directory while trying to stat /data/sharedlogs/otherhost/vcs
    [entpnerd@myhost ~]$ sudo lsattr /data/sharedlogs/otherhost/vcs
    [sudo] password for entpnerd: 
    lsattr: Not a directory while trying to stat /data/sharedlogs/otherhost/vcs
    
  6. Setting executable bits for the directory: As per the similar question, "Question marks showing in ls of directory. IO errors too", I tried to set the executable bits for the directory, but no luck with that either.

    [entpnerd@myhost ~]$ sudo chmod -R g+x /data/sharedlogs/otherhost/vcs
    [sudo] password for entpnerd: 
    chmod: cannot access ‘/data/sharedlogs/otherhost/vcs’: Not a directory
    [entpnerd@myhost ~]$ sudo chmod -R u+x /data/sharedlogs/otherhost/vcs
    chmod: cannot access ‘/data/sharedlogs/otherhost/vcs’: Not a directory
    [entpnerd@myhost ~]$ sudo chmod -R a+x /data/sharedlogs/otherhost/vcs
    chmod: cannot access ‘/data/sharedlogs/otherhost/vcs’: Not a directory
    

Any help would be greatly appreciated.

4
  • 2
    Is it mountpoint for unreachable remote filesystem (like NFS) or for local unreachable storage (either failed disk or FC storage)? Oct 13, 2017 at 7:06
  • 1
    Firstly, may I congratulate you on a beautifully-written and researched first question? Would that all first questions were like this one. Secondly, I'm sad to say that every time I've seen that on a local filesystem it's been a sign of a sick filesystem, so unmounting and fscking has been step one. If that fixes the FS enough to access that data, great; otherwise, as you say, it's nuke and restore from backups.
    – MadHatter
    Oct 13, 2017 at 7:23
  • Is this the same as serverfault.com/q/65616/208710 Oct 14, 2017 at 3:10
  • @DocSalvager I don't think that it's the same question because it is a "Not a directory" error, not an "IO Errors" error. Slightly different error, and the accepted (and other) answers didn't work for me.
    – entpnerd
    Oct 17, 2017 at 19:58

3 Answers 3

1

This may be an issue with the mounting service (e.g. Samba). Try restarting the Samba service on the remote host:

sudo service smb restart
3

I had this issue when running bind mounts on Docker. I restarted the Docker daemon and the file was correctly removed.

edit: I used WSL (Ubuntu 16.04) on Windows 10.

3
  • 1
    That sounds very unlikely.
    – kasperd
    Sep 21, 2018 at 7:29
  • Worked for me on Windows WSL with Ubuntu 16.04.
    – abettermap
    Nov 7, 2018 at 22:08
  • This works in cases where the file is mounted into a container. Restarting Docker releases the mount. Jun 25, 2020 at 14:38
1

Got same issue:

# ll /tmp/mtp
ls: cannot access /tmp/mtp: Input/output error
root@lenov01 ~ # ll /tmp
ls: cannot access /tmp/mtp: Input/output error
total 68
     ? d?????????  ? ?      ?          ?            ? mtp/
     2 drwxr-xr-x 25 root   root    4096 Nov 11 05:15 ../
393218 drwx------  2 root   root    4096 Nov 11 05:16 pulse-PKdhtXMmr18n/
393222 -r--r--r--  1 root   root      11 Nov 11 05:16 .X0-lock

The /tmp/mtp directory was created to acces an Android device storage:

# jmtpfs /tmp/mtp

I could get rid of this directory with:

# fusermount -u /tmp/mtp
1
  • Thanks for your answer @GM83. Did you actually manage to fix the directory or did you just remove the directory with the fusermount -u command?
    – entpnerd
    Nov 12, 2018 at 8:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .