5

I am trying to delete a directory using

rm -rf dirName

But I receive a bunch of errors like:

rm: cannot remove 'deleteMe/icarus/.nfs0000001bcf11514a0000cd45': Device or resource busy

When I try to find out the processes using this file with the command

lsof deleteMe/icarus/.nfs0000001bcf11514a0000cd45

There is no output. Any suggestions?

David
  • 163
  • Not even on the NFS server, or other hosts mounting the same directory? – Kusalananda Mar 25 '18 at 06:31
  • Sorry, what does the first part mean? – David Mar 25 '18 at 06:48
  • The directory that you are trying to delete is mounted from an NFS file server. If a program on another host that mounts the same directory from that server has a file open, you won't be able to delete the directory. – Kusalananda Mar 25 '18 at 06:49
  • Ohh I see. How do I check if a program on another host is mounting the directory and kill it? – David Mar 25 '18 at 06:51

2 Answers2

5

I had the same experience and I solved it with the aid of another thread on this same issue.

Read How to get over "device or resource busy"?

The contribution that helped me was:

ps -ef | grep name-of-busy-dir

Showed me the process and the PID (column two).

sudo kill -15 pid

Thereafter, delete your folder without any qualms.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Chimobi
  • 51
0

Another pretty much simple answer is following:

1. Close all your terminal windows (bash, shell, etc...)

2. Start a new terminal

3. Execute your command again e.g.:

rm -rf dirName

4. done

Hopefully it helps others!

  • 2
    Welcome to the site, and thank you for your contribution. Please note however that this would only work if there is no other user logged in who could be using the file or directory, and that this would also not work if it is a system process that occupies the resource rather than one started explicitly by the OP's user. – AdminBee Jul 01 '21 at 16:23
  • yes right, but on a single machine with single user, it should do it. A drastic answer will be a system restart or killing all processes that are using that resource – Manifest Man Jul 01 '21 at 16:35
  • it is not a suitable Answer – Anoob K Bava May 16 '22 at 16:46