X

Paulie's world in a blog

  • May 20, 2009

Cannot remove directory: File exists

Guest Author
If you try to delete a directory over NFS and get an error such as...
rm: cannot remove directory `asdf/': File exists

... you will notice that conventional methods won't be good enough to remove it.
$ chmod -R 777 asdf/
$ rm -rf asdf/
$ rm: cannot remove directory `asdf/': File exists

Usually there is a file like .nfs234B inside the directory than can be displayed with ls -la
$ ls -la
total 146
drwxr-xr-x 2 user group 512 2009-05-20 08:51 .
drwxr-xr-x 3 user group 512 2009-05-19 08:59 ..
-rwxr-xr-x 1 user group 134888 2009-05-18 12:45 .nfs234B

Removing this file only replaces it with another. There are two solutions: manually delete the file on the NFS server, or (if you don't have that type of access) kill its process.
$fuser -u asdf/.\*
asdf/.: 9070c(user)
asdf/..: 28690c(user) 24845c(user)
asdf/.nfs934B: 9070tm(user)

9070 is the offending process. Kill it with fire.
$ kill -9 9070

Should be able to remove that directory now.

Join the discussion

Comments ( 1 )
  • GabrielNar Tuesday, September 18, 2012

    Thanks for the information.

    Long Path Tool helped me in this situation. PathTooDeep.com


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.