When I try to delete an empty a directory with *rm - rf directory" I get a message telling me the directory is not empty therefore can’t be deleted.
How to delete, suggestions?
When I try to delete an empty a directory with *rm - rf directory" I get a message telling me the directory is not empty therefore can’t be deleted.
How to delete, suggestions?
Just to add .
It’s on an ext4 formatted partition
Did you try
rmdir /path/to/directory
or
rm -r /path/to/directory
?
Both, same error
Same error, not empty
Okay. Do you have the permission to delete it? As in it’s in your user’s home folder or you are using sudo
?
Edit: It shouldn’t matter with -rf
, but are you sure there is no hidden file left in this directory?
First thing is of course to check if you can see what the system seems to see:
ls -la directory
BTW, this is not a way of reporting that is appreciated here. Better copy/paste what you did and saw in your post. That means starting with the prompt/command line, all output up to and including the new prompt line (and of course using the Preformatted text functionality Posting code or preformatted text - Using Discourse - Discourse Meta). Only so can you earn trust in what you post.
ls -la
total 12
drwxr-xr-x 3 spaceboy spaceboy 4096 Aug 25 10:22 ./
drwxrwxr-x 3 spaceboy spaceboy 4096 Aug 25 10:32 …/
drwxr-xr-x. 3 spaceboy spaceboy 4096 Jan 10 2024 localhost/
I can only repeat:
To be clear , that is NOT as above, but something like:
henk@boven:~/test> l wireless/
total 28
drwxr-xr-x 2 henk wij 4096 Oct 14 2021 ./
drwxr-xr-x 10 henk wij 4096 Jun 24 19:39 ../
-r--r--r-- 1 henk wij 17534 Oct 14 2021 wireless-info
henk@boven:~/test>
I repeat: it starts with the prompt/command line (so we can see where you were, who you were and what you did), then all output, and then the new prompt so we can see it is complete.
And of course as copy/paste, to avoid any typos (because I doubt you did a correct copy/paste).
And also using the Preformatted text as explained in the link. I assume you used the button "
, but you should use the button </>
(or another method as mentioned in the link.
We are not getting anywhere near an explanation/solution in this way
ls -la /run/media/spaceboy/Virt_Machines/timeshift/snapshots/2024-01-08_22-00-02
total 12
drwxr-xr-x. 3 spaceboy spaceboy 4096 Jan 10 2024 ./
drwxr-xr-x 3 spaceboy spaceboy 4096 Aug 25 10:22 ../
drwxr-xr-x. 3 spaceboy spaceboy 4096 Jan 10 2024 localhost/
spaceboy@localhost.localdomain /run/media/spaceboy/Virt_Machines/timeshift/snapshots >
Looks much better. But why those dots .
after the drwxr-xr-x
in two of the lines? Strange! The more because in your first listing the dot in the first line isn’t there. Can you explain?
In any case, you see the directory is not empty because there is another directory localhost/
.
Of course that should be removed because of you used -rf
(but that is only what you say, NOT what you showed). Thus you have to check what is in localhost/
. And so on.
ls -l --context
ls(1) /security context
and chcon(1)
ls -l --context
total 4
drwxr-xr-x. 3 spaceboy spaceboy system_u:object_r:unlabeled_t:s0 4096 Jan 10 2024 localhost/
spaceboy@localhost.localdomain /run/media/spaceboy/Virt_Machines/timeshift/snapshots/2024-01-08_22-00-02 >
Also rm -r:
rm -r /run/media/spaceboy/Virt_Machines/timeshift/snapshots/2024-01-08_22-00-02/localhost
rm: cannot remove '/run/media/spaceboy/Virt_Machines/timeshift/snapshots/2024-01-08_22-00-02/localhost/.snapshots/1/snapshot/var/lib/flatpak/repo/objects/51/82c18929d175c0e04929c95babec044146f947a73d5f4rc3ce26ef6b8299d1.file': No such file or directory
You can NOT remove a directory with rm
. That is done with rmdir
.
It seems the problem is under whatever’s under localhost/
in this directory. What’s there, and who owns it?
My guess is there’s some file down there that isn’t owned by you, and thus rm
cannot remove it.
The output of find . -ls
from inside /run/media/spaceboy/Virt_Machines/timeshift/snapshots/2024-01-08/
might be informative.
find . -ls
5284441 4 drwxr-xr-x 3 spaceboy spaceboy 4096 Jan 10 2024 .
5284442 4 drwxr-xr-x 3 spaceboy spaceboy 4096 Jan 10 2024 ./localhost
5284450 4 drwxr-x--- 3 spaceboy spaceboy 4096 Jan 10 2024 ./localhost/.snapshots
5284467 4 drwxr-xr-x 3 spaceboy spaceboy 4096 Jan 10 2024 ./localhost/.snapshots/1
5284489 4 drwxr-xr-x 3 spaceboy spaceboy 4096 Jan 10 2024 ./localhost/.snapshots/1/snapshot
5284511 4 drwxr-xr-x 3 spaceboy spaceboy 4096 Jan 10 2024 ./localhost/.snapshots/1/snapshot/var
5547803 4 drwxr-xr-x 3 spaceboy spaceboy 4096 Jan 10 2024 ./localhost/.snapshots/1/snapshot/var/lib
5548153 4 drwxr-xr-x 3 spaceboy spaceboy 4096 Jan 10 2024 ./localhost/.snapshots/1/snapshot/var/lib/flatpak
5548301 4 drwxr-xr-x 3 spaceboy spaceboy 4096 Jan 10 2024 ./localhost/.snapshots/1/snapshot/var/lib/flatpak/repo
10226853 4 drwxr-xr-x 3 spaceboy spaceboy 4096 Jan 10 2024 ./localhost/.snapshots/1/snapshot/var/lib/flatpak/repo/objects
10226938 36 drwxr-xr-x 2 spaceboy spaceboy 36864 Jan 10 2024 ./localhost/.snapshots/1/snapshot/var/lib/flatpak/repo/objects/51
find: ‘./localhost/.snapshots/1/snapshot/var/lib/flatpak/repo/objects/51/82c18929d175c0e04929c95babec044146f947a73d5f4rc3ce26ef6b8299d1.file’: No such file or directory
spaceboy@localhost.localdomain /run/media/spaceboy/Virt_Machines/timeshift/snapshots/2024-01-08_22-00-02 >
Interesting output. What if you run it from in that directory as root?
Try this: sudo rm -rfv <directory>
As it is inside/run/media
it is probably a desktop mounted file system. Maybe mounted “readonly”?