While trying to delete a directory with "rm -rf", I kept getting "directory not empty". Puzzled, I looked why and I seem to have a "zombie" file stuck in there. I have no idea how to delete it. Is fdisk my only solution?
# rm -rf noc
rm: cannot remove directory `noc/INBOX/#msgs': Directory not empty
# rm -rf noc/INBOX/#msgs/000201E5.eml
# rm -rf noc
rm: cannot remove directory `noc/INBOX/#msgs': Directory not empty
# rm noc/INBOX/#msgs/000201E5.eml
rm: cannot remove `noc/INBOX/#msgs/000201E5.eml': No such file or directory
# cd noc/INBOX/#msgs/
# ls -la
ls: cannot access 000201E5.eml: No such file or directory
total 2248
drwx------ 2 root root 2293760 2013-08-27 21:55 .
drwx------ 3 root root 4096 2013-08-27 21:55 ..
-????????? ? ? ? ? ? 000201E5.eml
# ls -iN | cat -A
6346412 000201E5.eml$
# find . -inum 6346412 -exec rm -i {} \;
find: `./000201E5.eml': No such file or directory
# unlink 000201E5.eml
unlink: cannot unlink `000201E5.eml': No such file or directory
You should start by unmounting and using
fsck
to check the filesystem for corruption.If that does not repair it, then you can try examining the filesystem manually.
The
unlink
command simply calls the systemunlink()
function. Since it returns the errorNo such file or directory
, you can start by looking at exactly what the struct of the directory says about the file.ls
uses thereaddir()
call, and returns an error trying to read the dir entry. You would have to use thegetdents()
call directly to read the dir. Luckily there is a complete example inman 2 getdents
which you can compile and use without needing to modify anything.