Ubuntu – Delete directory indirectly inside of itself

filesystem

I have a directory inside itself. How do I delete it.

~/.local/share/Trash/files$ ls devices/
reg-dummy
~/.local/share/Trash/files$ ls devices/reg-dummy/
subsystem
~/.local/share/Trash/files$ ls devices/reg-dummy/subsystem/
devices

Also

~/.local/share/Trash/files$ find devices/ | head -n 20
devices/
devices/reg-dummy
devices/reg-dummy/subsystem
devices/reg-dummy/subsystem/devices
devices/reg-dummy/subsystem/devices/reg-dummy
devices/reg-dummy/subsystem/devices/reg-dummy/subsystem
devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices
devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy
devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem
devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices
devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy
devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem
devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices
devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy
devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem
devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices
devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy
devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem
devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices
devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy/subsystem/devices/reg-dummy

Also, although my brain can't solve the halting problem, it appears that sudo rm -rf devices goes on forever without producing output.

~/.local/share/Trash/files$ sudo rm -rf devices
^C~/.local/share/Trash/files$

Same thing for perl -e 'use File::Path qw(remove_tree); remove_tree("$ENV{HOME}/.local/share/Trash/files/devices")'.
Same thing for du -s devices/. Same thing for du -sch ~/.local/share/Trash/
Other commands

$ cd ~/.local/share/Trash/files/devices/reg-dummy/subsystem/devices/
$ ls -ldi 
8131921 drwxr-xr-x 3 theking theking 4096 Mar 17 19:43 .
$ cd reg-dummy/subsystem/devices/
$ ls -dli
8131926 drwxr-xr-x 3 theking theking 4096 Mar 17 19:43 .


$ find .local/share/Trash/files/ -maxdepth 1 -delete
find: cannot delete `.local/share/Trash/files/devices': Directory not empty
find: cannot delete `.local/share/Trash/files/': Directory not empty

I don't want it stuck in my trash forever!

Note: I was making a crude backup of a computer by simply using scp, and but I ran out of space and then this happened.

Best Answer

The output of ls -ldi will show the inode number of the directory. If the directory within the directory really has the same inode number as its ancestor, rather than just the same name, then your filesystem is corrupt and you will need to boot into rescue mode and fsck it.

Related Question