简体   繁体   English

自动解决rm cannot remove path: device or resource busy错误

[英]Automatically solve rm cannot remove path : device or resource busy error

I am trying to remove a directory /path/to/dir using the rm -rf command.我正在尝试使用rm -rf命令删除目录/path/to/dir 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:它将返回与进程关联的 PID 的内容:

COMMAND   PID
python    28594

I then kill the PID and try again to delete, but I still get the initial error.然后我杀死 PID 并再次尝试删除,但我仍然得到初始错误。

How to force the script to delete /path/to/dir automatically within a script, without manual intervention?如何强制脚本在脚本中自动删除/path/to/dir而无需手动干预?

This worked for me:这对我有用:

lsof +D /path

That will recurse through the filesystem under /path, so beware doing it on large directory trees.这将通过 /path 下的文件系统递归,所以要小心在大目录树上这样做。

Once you know which processes have files open, you can exit those apps, or kill them with the kill(1) command.一旦知道哪些进程打开了文件,就可以退出这些应用程序,或使用 kill(1) 命令终止它们。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM