3

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?

David Z
  • 6,785

3 Answers3

1

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.

1

Have you tried deleting the inode directly?

$ ls -iN | cat -A
794539 $
$ find . -inum 794539 -exec rm -i {} \;
0

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.

Avery Payne
  • 2,541