Undeletable directory

Everything I’ve tried (always with superuser privileges) has failed:

# rm -rf /path/to/undeletable
rm: cannot remove ‘/path/to/undeletable’: Is a directory
# rmdir /path/to/undeletable
rmdir: failed to remove ‘/path/to/undeletable’: Device or resource busy
# lsof +D /path/to/undeletable
lsof: WARNING: can't stat(/path/to/undeletable): Permission denied
lsof 4.86
 latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
 latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
 latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
 usage: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-f[gG]] [+|-e s]
 [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]
[+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]
Use the ``-h'' option to get more help information.

When I try any of the above without superuser privileges the results are basically the same. The only difference is that the initial WARNING message from the lsof command has Input/output error instead of Permission denied. (This minor difference is in itself already puzzling enough, but, whatever…)

How can I obliterate this directory?

Asked By: kjo

||
# rm -rf /path/to/undeletable
rm: cannot remove ‘/path/to/undeletable’: Is a directory

rm calls stat(2) to check whether /path/to/undeletable is a directory (to be deleted by rmdir(2)) or a file (to be deleted by unlink(2). Since the stat call fails (we’ll see why in a minute), rm decides to use unlink, which explains the error message.

# rmdir /path/to/undeletable
rmdir: failed to remove ‘/path/to/undeletable’: Device or resource busy

“Device or resource busy”, not “Directory not empty”. So the problem is that the directory is used by something, not that it contains files. The most obvious “used by something” is that it’s a mount point.

# lsof +D /path/to/undeletable
lsof: WARNING: can't stat(/path/to/undeletable): Permission denied

This confirms that stat on the directory failed. Why would root lack permission? That’s a limitation of FUSE: unless mounted with the allow_other option, FUSE filesystems can only be accessed by processes with the same user ID as the process that provides the FUSE driver. Even root is hit by this.

So you have a FUSE filesystem mounted by a non-root user. What do you want to do?

  • Most likely you’re just annoyed by that directory and want to unmount it. Root can do that.

    umount /path/to/undeletable
    
  • If you want to get rid of the mount point but keep the mount, move it with mount --move. (Linux only)

    mkdir /elsewhere/undeletable
    chown bob /elsewhere/undeletable
    mount --move /path/to/undeletable /elsewhere/undeletable
    mail bob -s 'I moved your mount point'
    
  • If you want to delete the files on that filesystem, use su or any other method to switch to that user, then delete the files.

    su bob -c 'rm -rf /path/to/undeletable'
    
  • If you want to delete the files that are hidden by the mount point without disrupting the mount, create another view without the mount point and delete the files from there. (Linux only)

    mount --bind /path/to /mnt
    rm -rf /mnt/undeletable/* /mnt/undeletable/.[!.]* /mnt/undeletable/..?*
    umount /mnt
    
Categories: Answers Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.