Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

I'm trying to delete a supposedly empty directory on a ReiserFS filesystem, but I can't because rm keeps complaining that the directory isn't empty.

$ rm -rf thedirectory
rm: cannot remove `thedirectory': Directory not empty
$ ls -a thedirectory
         .  ..

The problem is, everything I do to try to determine what actually is in the directory seems to show that there are three files with no names. For example:

$ cd thedirectory
$ ls
ls: cannot access : No such file or directory
ls: cannot access : No such file or directory
ls: cannot access : No such file or directory

$ find .
$ ls -N | cat -A

Since I can't get filenames, I can't run stat or anything useful on these mystery files. A stat on the directory itself yields seemingly normal results:

$ stat .
  File: `.'
  Size: 192             Blocks: 0          IO Block: 4096   directory
Device: 807h/2055d      Inode: 825484      Links: 2
Access: (0755/drwxr-xr-x)  Uid: ( 1000/ diazona)   Gid: ( 1000/ diazona)
Access: 2012-01-27 16:32:45.000000000 -0500
Modify: 2012-01-27 16:31:58.000000000 -0500
Change: 2012-01-27 16:31:58.000000000 -0500

I suppose some kind of filesystem corruption is involved, which probably means I have to shut down, boot from a live USB drive, and try my luck with reiserfsck. But is there any easier way to deal with this?

share|improve this question
Have you tried rm -rf /path/to/thedirectory? – Andrew Lambert Jan 27 '12 at 22:21
Silly me, I completely forgot to include that output ;-) but yes, that was what brought my attention to the problem in the first place. – David Z Jan 27 '12 at 22:23
What does ls -N | cat -A print? – Keith Thompson Jan 27 '12 at 22:26
I've edited that into the question too. – David Z Jan 27 '12 at 22:28

Giving the -f flag to rm means it won't complain when it can't do something, perhaps something such as trying to remove a file owned by another user (e.g. root) or you don't have write permissions to the directory. sudo rm -rf /path/to/thedirectory will no doubt nuke the directory and the files therein. ls -B thedirectory | cat -ve may also be illuminating.

share|improve this answer
No luck, running with sudo fails the same way. – David Z Jan 27 '12 at 23:34
Then you've got a fault in the filesystem. fsck reports nothing amiss? – Andrew Beals Jan 27 '12 at 23:44
I haven't run fsck yet, because I need to unmount the filesystem first. – David Z Jan 27 '12 at 23:47

Have you tried deleting the inode directly?

$ ls -iN | cat -A
794539 $
$ find . -inum 794539 -exec rm -i {} \;
share|improve this answer
looking at the timestamp, i seem to be late to the party :-/ – Christopher Neylan Feb 4 '12 at 15:31
Sorry, I never noticed this here. I'm a little later in responding, I guess :-P I don't have access to the filesystem in question anymore, but I don't think this would work because it needs the filename to pass to rm. It might have worked to use find's -delete option, and if I ever get the chance to test this, I'll try it. – David Z Jun 14 at 19:58

You can see all files with

ls -la /name/of/path

...which will give you a long listing, including any dot files.

To remove a directory and everything inside of it, including other subdirectories, use:

rm -rf /name/of/path/*

...although be careful if you plan to use the wildcard character, which leads to the (in)famous statement:

rm -rf *

...which is dangerous, indeed, even for "normal users". If you ever need to use the wildcard character, I would suggest:

rm -rf /name/of/path


rm -rf ./*

... the last with the dot-slash being done with the assumption that you are "inside" the directory you want to empty'll still need to move down one directory and remove it from outside of itself.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .