自动求解RM无法删除路径:设备或资源繁忙错误

发布于 2025-01-23 07:08:14 字数 488 浏览 5 评论 0 原文

我正在尝试使用 rm -rf 命令删除目录/path/to/dir 。 会发现错误

rm: cannot remove '/path/to/dir/.nfsdda293a660f276ca0000000a': Device or resource busy

不幸的是,经过一番研究,我

lsof /path/to/dir/.nfsdda293a660f276ca0000000a

,我意识到我需要在删除该文件之前找到使用此文件的过程:哪个将与该过程相关的PID返回某些内容:

COMMAND   PID
python    28594

然后,我杀死PID并尝试尝试再次删除,但我仍然会收到初始错误。

如何强制脚本删除/path/to/dir 在脚本中自动删除,而无需手动干预?

I am trying to remove a directory /path/to/dir using the rm -rf command.
Unfortunately I get the error

rm: cannot remove '/path/to/dir/.nfsdda293a660f276ca0000000a': Device or resource busy

After a little bit of research, I realized that I need to find which process is using this file before I can delete it:

lsof /path/to/dir/.nfsdda293a660f276ca0000000a

which will return something with the PID associated with the process:

COMMAND   PID
python    28594

I then kill the PID and try again to delete, but I still get the initial error.

How to force the script to delete /path/to/dir automatically within a script, without manual intervention?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

生活了然无味 2025-01-30 07:08:14

这对我有用:

lsof +D /path

这将通过 /路径下的文件系统反复出现,因此请注意在大型目录树上进行操作。

一旦知道哪些进程打开文件,就可以退出这些应用程序,也可以使用杀死(1)命令杀死它们。

信用:

This worked for me:

lsof +D /path

That will recurse through the filesystem under /path, so beware doing it on large directory trees.

Once you know which processes have files open, you can exit those apps, or kill them with the kill(1) command.

Credit:
https://unix.stackexchange.com/questions/11238/how-to-get-over-device-or-resource-busy

诠释孤独 2025-01-30 07:08:14

这里有很多复杂的答案使每个人都感到困惑,请只做以下操作。

umount directoryname

然后再试一次
例如

rm -rf directoryname

With so many complicated answers on here which is confusing everybody, please just do the following.

umount directoryname

then try again
e.g.

rm -rf directoryname
聆听风音 2025-01-30 07:08:14

如果 @hayden 答案对您没有帮助(毫无疑问或此类命令),此命令可以方便:

umount /path

信用

In case the @Hayden answer didn't help you (returns nothing or such), this command can be handy:

umount /path

credit

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文