How do I delete a directory that appears to contain nameless files?

3

2

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

Posted 2012-01-27T22:11:27.223

Reputation: 5 688

Have you tried rm -rf /path/to/thedirectory? – Andrew Lambert – 2012-01-27T22:21:10.930

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 – 2012-01-27T22:23:01.523

What does ls -N | cat -A print? – Keith Thompson – 2012-01-27T22:26:22.047

I've edited that into the question too. – David Z – 2012-01-27T22:28:08.087

Answers

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.

Andrew Beals

Posted 2012-01-27T22:11:27.223

Reputation: 219

No luck, running with sudo fails the same way. – David Z – 2012-01-27T23:34:29.093

1Then you've got a fault in the filesystem. fsck reports nothing amiss? – Andrew Beals – 2012-01-27T23:44:35.213

I haven't run fsck yet, because I need to unmount the filesystem first. – David Z – 2012-01-27T23:47:06.290

1

Have you tried deleting the inode directly?

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

Christopher Neylan

Posted 2012-01-27T22:11:27.223

Reputation: 701

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 – 2016-06-14T19:58:59.970

looking at the timestamp, i seem to be late to the party :-/ – Christopher Neylan – 2012-02-04T15:31:16.617

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

Posted 2012-01-27T22:11:27.223

Reputation: 2 371