14

A lot of time when I delete a folder, it says cannot be deleted because of .nfs files.

Error - Device or resource busy

How can I delete a folder ignoring these errors (is there any flag in rm command)? Or I would have to find out the process using it, and first kill that process?

In that case how can I make it work to remove entire directories?

roaima
  • 107,089
  • 14
  • 139
  • 261
Novice User
  • 1,331
  • 5
  • 14
  • 23
  • 3
    You could try running `fuser /path/to/.nfs` to check which process is using the .nfs file. – mtak May 02 '14 at 09:13
  • what difference would it make than using lsof ? – Novice User May 02 '14 at 12:22
  • For this, none I guess. But I don't understand why you're asking that. – mtak May 02 '14 at 12:25
  • 1
    I want to use some script which deletes all files/folders inside a directory, and also clear up any .nfs files present. – Novice User May 03 '14 at 04:52
  • Can you give an example of a .nfs file name? NFS commonly uses .nfs### files for internal record keeping, for example (where ### is some long string of digits). Also would be useful to know if NFS is involved, either the file system you are using is NFS mounted on your host, or if it is NFS exported to some other host. – Peter Aug 04 '14 at 01:11
  • Thanks @mtak fuser worked nicely! I will show example in a new answer . . elsewhere as this Q marked as duplicate. – gaoithe Aug 28 '19 at 09:57
  • Example of using fuser and successful remove here: a tracker-extract process was holding files open on the nfs disk. https://unix.stackexchange.com/questions/231074/removed-a-vagrant-file-and-now-i-see-nfs0000000000b869e300000001/537840#537840 – gaoithe Aug 28 '19 at 10:11
  • @Peter Example of file name ```.nfs00000000018d307a00000369``` – gaoithe Aug 28 '19 at 10:11

1 Answers1

6

You can remove whole folder with rm -rf <folder name>, where r means recursive and f forcefully. See man page of rm for better understanding.

But if the error Device or resource busy is coming that means that the folder is in use by some process. So you first need to find that process and kill it, and then you can remove the folder.

Eddie C.
  • 425
  • 4
  • 7