9

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.

20
  • Please show us the command you tried to delete it with and the error it gave you. What does rm -rf devices do?
    – terdon
    Mar 18, 2014 at 21:08
  • Please also add the output of ls -dli devices and ls -dli devices/reg-dummy/subsystem/devices/
    – terdon
    Mar 18, 2014 at 21:27
  • 3
    The first command should have been ls -ldi devices, not device. I am trying to see if these are actually hard links (the same inode). However, be aware that if this is a large directory, rm -rf will take a long time but will eventually work. If the issue here is circular links, you will get an error message about infinite recursion. If there's no error message, just let rm -rf run its course.
    – terdon
    Mar 18, 2014 at 21:52
  • 7
    @terdon: I thought Linux (Ubuntu, at least) doesn't allow hard-linked directories? Mar 18, 2014 at 22:28
  • 2
    I'm just assuming you tried with the nautilus built-in "empty trash" button ? (maybe they thought of that kind of things when writing nautilus^^)
    – MrVaykadji
    Mar 20, 2014 at 0:20

3 Answers 3

3

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.

1

I still think that rm -rf will work if you give it enough time but if not, one or both of these should:

perl -e 'use File::Path qw(remove_tree); 
        remove_tree("$ENV{HOME}/.local/share/Trash/files/devices")'`

 

find .local/share/Trash/files/ -delete

You can make sure that something is happening if you use rm -rfv ~/.local/share/Trash/files/devices at least that will let you know that files are being deleted.

Anyway, this can't be a hardlink problem (despite my very wrong comment) because directories can't be hardlinked under Linux. In general, when you have infinite recursion, as can happen with softlinks, you will get a message to that effect, that does not appear to happen.

The other possibility I can think of is that the Trash folder is some strange system of its own. I don't really know how it works, I never use it. However, you might have better luck deleting the top level files directly instead of targeting the problematic directory:

rm -rf ~/.local/share/Trash/* 

You should also try emptying the Trash folder from the GUI, just select Trash and click on "Empty Trash", see if that works.

9
  • They both failed. Question revised. Mar 19, 2014 at 20:43
  • @PyRulez how large is this directory? Neither the perl script nor the rm will produce any output. How long did they run for? I also updated the find command, the previous one was wrong, sorry. Have a look at the updated answer. Finally, we're working blind here. Please update your question with the output of ls -l where you have used ls, also show the result of du -sch ~/.local/share/Trash/ so we know the size.
    – terdon
    Mar 19, 2014 at 22:49
  • I couldn't find the size. Mar 20, 2014 at 0:10
  • @PyRulez try du -sch ~/.local/share/Trash/ that will give you the size. And please add all the stuff the various comments have asked for, they're needed so we can understand what's going on.
    – terdon
    Mar 20, 2014 at 0:12
  • @tedron I have been. Mar 20, 2014 at 0:15
0

(I am confident this will work and as I am going to travel right now, I will leave this as an answer that I can delete in the future if it does not work.)

  1. First, to be safe, run

    find ~/.local/share/Trash/files/devices/ -exec echo {} \;
    
  2. Second, if the output of "1" did not show any important file, then run

    find ~/.local/share/Trash/files/devices/ -exec rm {} \;
    
  3. The final step would be

    find ~/.local/share/Trash/files/devices/ -empty -type d -delete
    

You must log in to answer this question.

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