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?
lsof
to get the PID to kill and kill it the same method as you would manually. – Atlifuser -k
to do both steps (find the process and kill it) at once? – Deranged