Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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? –  Amazed 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
add comment

3 Answers

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
1  
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
add comment

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
add comment

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

or

rm -rf ./*

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

share|improve this answer
add comment

Your Answer

 
discard

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.