I have noticed that after running my Java program, there is a dot file
that cannot be deleted. (I use linux). Following is the screen shot:
$ls -a
. .. .nfs009da645000007c3
$rm .nfs009da645000007c3
rm: remove regular file `.nfs009da645000007c3'? y
rm: cannot remove `.nfs009da645000007c3': Device or resource busy
I guess that I didn't close some PrintWriter or what. The Java program
ends normally. Can you give me some suggestions?
This file is an artifact of the NFS (network) file system that you
are almost certainly using. This type of file entry is created
when a normal file is deleted (unlinked) while some process
(presuming your Java program) has it open. This is a common
strategy for creating of temporary files by UNIX programs. If you
were using the file on a local file system, the removal would
simply result in a "file" that still existed but did not have a
file system entry. The advantage of this strategy is that the OS
will remove the "file" when the file is closed -- even if the close
is caused by an abnormal exit.
NFS was designed as a "state-less" file system. This has several
advantages, but one of the disadvantages is that is doesn't handle
"state-ful" operations. This type of removal requires the retention
of the knowledge that the original file system entry has been
removed, but the data must still be retained. NFS handles this
by renaming the original file to the form ".nfs<something>" instead
of actually removing it.
It should go away when the process completes, but if it doesn't
for some reason, there are a couple of options. On many/most
systems that serve NFS clients, there is a daemon job that sweeps
the file systems and deletes such files after a couple of days.
If you are sure that no programs are still active that might access
this file, it is safe for you to delete it yourself -- although
if you do this while some process still have the file open, you
will simply iterate on the creation of the strangely named files.
You probably also would be able to delete it from a program running
on the server system.
Just a little more detail if you're interested: The use case to
consider here is that you have an NFS-mounted file open that you
have removed. Now consider that the server is rebooted for whatever
reason. Your client-side file system still needs to be able to
reopen the file, and it does so by using the ".nfs<something>"
form of name.
Here are some random references that Google came up witH;
http://www.cs.indiana.edu/Facilities/FAQ/General/dotnfs.html
http://www.seas.upenn.edu/cets/answers/nfs-files.html
- dmw