Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question
Have you checked for filesystem corruption using fsck? – 200_success Oct 11 '13 at 17:58
Can you mv the offending file somewhere else? That doesn't solve the problem, but it would at least get it out of your way. – Keith Thompson Oct 11 '13 at 19:10
You can use clri and then run fsck – mpez0 Oct 11 '13 at 19:33
up vote 3 down vote accepted

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 system unlink() function. Since it returns the error No such file or directory, you can start by looking at exactly what the struct of the directory says about the file.

ls uses the readdir() call, and returns an error trying to read the dir entry. You would have to use the getdents() call directly to read the dir. Luckily there is a complete example in man 2 getdents which you can compile and use without needing to modify anything.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.