削除できないディレクトリ

削除できないディレクトリ

私が試したすべてのもの(常にスーパーユーザー権限で)が失敗しました。

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

スーパーユーザー権限なしで上記の操作を試みると、結果は基本的に同じです。唯一の違いは、lsofコマンドの最初の警告メッセージInput/output errorですPermission denied

このディレクトリをどのように削除できますか?

ベストアンサー1

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

rmディレクトリ(削除される予定)かファイル(削除される予定)かをstat(2)確認するために呼び出されます。呼び出しが失敗するため(後で説明しますので、エラーメッセージを説明する)を使用することにします。/path/to/undeletablermdir(2)unlink(2)statrmunlink

# 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

これはstatディレクトリエラーをチェックします。ルートに権限がないのはなぜですか?これはFUSEの制限です。allow_otherこのオプションを使用してインストールしないと、FUSEファイルシステムはFUSEドライバを提供するプロセスと同じユーザーIDを持つプロセスからのみアクセスできます。根までも影響を受けます。

したがって、root以外のユーザーがFUSEファイルシステムをマウントしました。何をしたいですか?

  • おそらくあなたはこのディレクトリに迷惑をかけて削除したいでしょう。根はこれを行うことができます。

    umount /path/to/undeletable
    
  • マウントポイントを削除してマウントポイントを維持するには、Move itを使用しますmount --move。 (Linux のみ)

    mkdir /elsewhere/undeletable
    chown bob /elsewhere/undeletable
    mount --move /path/to/undeletable /elsewhere/undeletable
    mail bob -s 'I moved your mount point'
    
  • そのファイルシステムからファイルを削除するには、su別の方法を使用してそのユーザーに切り替えてファイルを削除します。

    su bob -c 'rm -rf /path/to/undeletable'
    
  • マウントを中断せずにマウントポイントによって隠されたファイルを削除するには、マウントポイントを含まない別のビューを作成し、ここからファイルを削除します。 (Linux のみ)

    mount --bind /path/to /mnt
    rm -rf /mnt/undeletable/* /mnt/undeletable/.[!.]* /mnt/undeletable/..?*
    umount /mnt
    

おすすめ記事