Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying to delete some files and folders, but I can't because the system keeps re-creating the files.

All these files are named .nfsXXXX, where XXXX is some random 4-character hexadecimal number. Whenever I delete one of these files, it creates another one with a different name but the same contents.

This is happening in several unrelated directories. What could be causing this and how can I fix it?

share|improve this question
    
See also Where do open file handles go when they die? –  Gilles Dec 30 '11 at 0:59
add comment

3 Answers 3

up vote 5 down vote accepted

Quoting verbatim from https://uisapp2.iu.edu/confluence-prd/pages/viewpage.action?pageId=123962105 :

Under linux/unix, if you remove a file that a currently running process still has open, the file isn't really removed. Once the process closes the file, the OS then removes the file handle and frees up the disk blocks. This process is complicated slightly when the file that is open and removed is on an NFS mounted filesystem. Since the process that has the file open is running on one machine (such as a workstation in your office or lab) and the files are on the file server, there has to be some way for the two machines to communicate information about this file. The way NFS does this is with the .nfsNNNN files. If you try to remove one of these file, and the file is still open, it will just reappear with a different number. So, in order to remove the file completely you must kill the process that has it open.

If you want to know what process has this file open, you can use 'lsof .nfs1234'. Note, however, this will only work on the machine where the processes that has the file open is running. So, if your process is running on one machine (eg. bobac) and you run the lsof on some other burrow machine (eg. silo or prairiedog), you won't see anything.

share|improve this answer
add comment

These .nfsXXXX files are a normal part of NFS operation. I won't rehash what @Keith Thompson wrote, but one thing to do is not delete them right away, set up a cron job to remove them if they have not been accessed in some time:

find dir .name .nfs\* -atime +3 -delete
share|improve this answer
add comment

Another option is to delete the .nfsXXXX files from the server side.

share|improve this answer
    
would not that make client write/open request fail and still cause more problems? –  Nikhil Mulley Jan 18 '12 at 7:09
    
yes, it shall invalidate the open fds, but who cares? the files are gone from the namespace anyway. –  yarek Jan 18 '12 at 10:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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