12

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?

  • 2
    You could try running fuser /path/to/.nfs to check which process is using the .nfs file. – mtak May 2 '14 at 9:13
  • what difference would it make than using lsof ? – Novice User May 2 '14 at 12:22
  • For this, none I guess. But I don't understand why you're asking that. – mtak May 2 '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 3 '14 at 4: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 4 '14 at 1:11
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.

| improve this answer | |
  • Will rm -rf able to delete the files even if they say "Device or Resource busy" ? – Novice User May 2 '14 at 7:10
  • Yes, And just try it on your set-up and check it out. – ravibhuva9955 May 2 '14 at 7:26
  • 2
    Good suggestion. I just tried. It doesn't work. Thanks. – Novice User May 2 '14 at 7:58
  • 4
    No, you can't delete .nfsXXX files. Or more precisely, you can delete them, but they'll come back immediately. You need to close the program that has them open, and that program could be running on any client that has this directory mounted over NFS. – Gilles 'SO- stop being evil' Aug 15 '16 at 23:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.