Is file manager "Send to trash" more permissive than "rm"?
Hi,
There is a useful directory test I don't want to be able to delete as a simple user because as it is in my ~/Downloads directory I could decide to swipe all in there regularly and swipe it along too... (NB: move test elsewhere is not conceivable here) The easiest way I found to achieve that is to create a .protected file inside ~/Downloads/test whith the immutable flag (chattr +i). So I'm still able to create files in it, modify or delete them but I won't be able to delete the directory itself. rm -rf ~/Downloads/test is not allowed, great, but I can still send ~/Downloads/test to trash via my GUI file manager (Thunar). I can even empty the trash afterwards... Why? How to prevent deletion by GUI as well please? Thanks in advance :) |
Should be able to do that by setting its attribute, or chmod it.
man chmod man attrib |
Quote:
Quote:
|
I don't use the so-called Trash can (part of gvfs afair?).
To understand why that doesn't work as expected, you should research that, and not the core utilities that do work as expected. |
You can't easily prevent deletion by the GUI file manager - unless you want to make Downloads read only - which would be a strange thing to do.
Typically, deleting a file or directory by a GUI just moves it to ~/.local/share/Trash/. If you delete that directory, it gets automatically recreated. Moving a directory is fast because it doesn't need to look at the contents. BTW I have a Desktop directory in ~/ I wonder what would happen to my desktop if I deleted it in my GUI? Decided not to test it.:rolleyes: |
That immutable ".protected" file does not prevent renaming the directory, and that's basically all that hapens when a directory is moved to Trash.
|
Quote:
But on my other than home trash bins get messed up some how, I don't really pay that much attention to it. because when I remove something I want it deleted, not put out of sight only to have to empty the trash again to finally delete it. there is However a app called trash-cli that you can use. Variety uses it to delete files. Code:
$ aptsearch trash-cli make ownership of dir roots and change permissions so the user can manipulate files within same said directory. even if it is in your own home dir? testing that theory right now. that does not work because user is part owner in its own home dir. |
Quote:
Code:
apt-cache search trash-cli trash-cli seems a bit tedious to use, although I suppose it could have a use inside a script. |
Quote:
Code:
alias aptsearch='sudo apt-cache search ' it takes the tediousness out of it. :D |
Quote:
However, it doesn't explain why I can empty the trash afterwards! Quote:
But why do you say that moving to trash rename the directory? |
Renaming is done by the mv command.
It just moves the directory entry somewhere else. Appears to operate like a delete and create. :) So a mv from one path to the same path simply appears to rename the file or directory. |
^ Yes, I'm ok with that but that's the path that is "renamed"/changed, not the filename or directoryname itself ;)
|
Quote:
Quote:
|
I tried creating a file in my home directory and arranged for it to be owned by root, with root read-only permissions.
My user GUI happily moved the file to Trash. All quite understandable, so far. Still as user, I asked the GUI to empty the Trash - which it did. Assuming the File Manager doesn't have a SETUID component component, how did I gain the necessary write permission to remove that file? (It didn't get put in ~/.local/share/Trash/expunged) |
Testing with Debian 10, KDE 5.14.5, Dolphin 18.08.0
Creating a file like this... Code:
sudo touch testing-deleting-files However, the file can also be removed with rm. Neither "sudo locate testing-deleting-files" nor "sudo locate expunged" returned any results (after an updatedb of course). Creating a file like this... Code:
sudo touch testing-deleting-files Creating a file inside a directory like this... Code:
mkdir testing-deleting-files |
All times are GMT -5. The time now is 08:04 PM. |