Tuesday, June 5, 2012

Cannot remove directory: File exists

I was trying to remove a directory and got error: "cannot remove directory 'logs/': File exists"
$chmod -R 777 logs/
$rm -rf logs/
$rm: cannot remove directory 'logs/': File exists
Checked the logs folder content and found out that there was .nfs*** file in this, when I manually deleted this file, it was recreated immediately and the timestamp of the file was not current, it was same of which I just deleted.
$ls -lrta
total 20K
drwxrwxrwx 3 test vishnu 4.0K May  3 03:27 ..
-rwxrwxr-x 1 test vishnu  11K May  3 03:27 .nfs29682
drwxrwxr-x 2 test vishnu 4.0K Jun  4 23:17 .
To solve this issue, we need to find out which process is using this file and delete that process.
$/usr/sbin/fuser -u logs/.*
logs/.:    
logs/..:    
logs/.nfs29682:     23142m(test)
23142 is the process which is using this directory, we need to kill it.
kill -9 23142
now delete the directory, it will be deleted successfully.
$rm -rf logs/
$

No comments: