How to release space utilized by .nfs files under NFS

On Linux/UNIX systems if you delete a file that a currently running process still has open, the file isn’t really deleted or removed . Once the process closes the file, the OS then removes the file handle and free up the disk blocks.This process works slightly other way 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 location A ) 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 .nfsNNNNNN 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 we must must kill that process which is currently using it.

Note: These .nfsNNN files are usually created by nfs client for its own operation functionalities. These files are used by nfs client to keep track of the files which are to be deleted when nfs client close the process. .nfsNNN files concept will disappear in NFSv4

You can list down these files by running ‘ ls -lah ‘ command from nfs share mounted directory, the process needs to be killed which has open these files in order to release space .

If you want to know which process has this file open, you can use below lsof command

$ lsof | grep -i .nfs1234

Example :

 $ echo testfile > foo
 $ tail -f foo
 $ rm foo
 $ ls -A
 $ rm .nfsC13B
 $ ls -A

$ lsof .nfsC13B
 tail   1182 jack    0r  VREG  186,6   5 1200718   .nfsC13B%

Let’s suppose we create a file with the name “foo” under nfs mounted directory and then listing the content using tail command and after that we try to delete the file using rm command. Execute “ls -A” command to list .nfsNNN file and if we try to delete .nfsNN file then nfs client will automatically create .nfs file.

So once you find .nfsNN file and want to delete it permanently then killed that process that has the file open, the .nfs file will go away automatically. In the above example, when you kill the tail process i.e PID 1182 , the .nfsC13B file will disappear.

To kill a process in Linux distributions use kill command, so to kill a process of PID 1182, execute the beneath command,

$ sudo kill -9 1182

Leave a Comment