[SOLVED] How does Linux remember that there is trash in the trash can?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How does Linux remember that there is trash in the trash can?
Perhaps this question belongs in the security forum (really need a privacy forum) but I guess it will get reasonable exposure here.
I generally do not use the trash can feature. When I delete something I DELETE it. That said I sometimes accidentally trash instead of delete or perhaps an application sends to trash when asked to delete. Bottom line, I see that there is trash in the trash can icon (CentOS 7.5 with Mate desktop). Easy enough to empty trash. Except...
Recently I noticed that the trash can icon was indicating something in trash. I opened trash but nothing was there. Eventually I figured out that I must have deleted something on a removable storage device and then unmounted/removed the device before doing the empty trash drill. I reinserted the device (flash drive) and the "trashed" items appeared in Trash.
My research has found that trash is supposed to be "stored" in ~/.local/share/Trash. I looked in said directory and it subdirectories and found nothing with or without the removable device mounted. Further investigation found the directory /.Trash-1000 on the file system of the removable device. The trashed files were there. This at least relieved my concern that meta-data from a removable device might be leaked to the fllesystem of the hard drive in the PC. Still I am wondering...
How does the OS know that a removable device is floating around the universe with "trashed" files on it?
Ken,
I don't know the answer...but wanted to point out that the Trash is not a function of the OS, but rather of the desktop (you said Mate, yes?) A machine without a desktop doesn't have a Trash.
I'd suspect some kind of global thing to turn on that flag, but I don't really know.
Unlike Windows, Linux pretty effectively separates the Desktop Environment from the OS. For example, I'm running CentOS 7.4, but am using the Cinnamon desktop.
You are correct. I did not mean to say OS but I was tired of typing and OS was shorter that desktop environment
As I wrote the original post I was still doing some searching. My initial concern was that the meta-data re. where does this deleted belong (where should it be restored to) might be stored on the main file system. This would not be a good thing if the location was on an encrypted file system which had been locked or an encrypted device which had been removed - if that device contained sensitive information. It appears that that is not the case so it has sort of devolved into a curiosity.
even if you delete a file properly, its contents can almost always still be recovered, so the only real security would come from using something like shred.
about Trash directories on removable media, this topic has been discussed dozens of times during the last 15 years or so, please do some research.
I have a similar structure on /home/ken/.local/share/Trash. In my case the directories are expunged, files and info. It seems to handle files ONLY on the /home file system (which is on its own partition). Actually I guess it only handles MY files. Each other partition or file system has a directory /.Trash-000 which handles trashed files for that particular file system.
Thanks ondoho,
My question was not about the ability to recover a "deleted" file. I do on occasion use shred. Generally I think ahead and prepare an encrypted file system or Vera Cryot type container before writing a sensitive file.
I have gotten to the bottom of my issue. I trashed a file on the flash drive on my CentOS 7.5 Mate machine. I ejected it and the trash can stayed "full." I placed the flash drive in an Ubuntu Mate 18.04 machine. The trash can icon changed from empty to full. The trashed file appeared in the trash directory when I opened it in Caja. When I went to eject the flash drive I was asked if I wished to empty trash before ejecting the device. CentOS did NOT do so. That is the source of my confusion.
I guess I need to file a bug - I guess with epel as that is where I installed the Mate desktop environment from. It does not seem to be a Mate specific issue as it works on Ubuntu.
It's quite safe to delete the Trash folder. This will give you your storage back.
It will be automatically re-created next time you delete a file via the GUI.
I am not concerned with any lost space. The point is that the trash can icon is implying that there are some trashed but undeleted files on my computer. In fact they are on the SD card which is back in my DSLR camera. As I described previously Ubuntu handles this "properly." I need to try Fedora + Mate and CentOS + Gnome3 to try and narrow down who is at fault in my situation.
As I stated earlier I found my "home" trash at: /user/ken/.local/share/Trash
If I "delete" a file in my home directory tree it disappears into /user/ken/.local/share/Trash/files. I have a couple of other filesystems. /quitelarge and /xtra. Each is contained on a different drive. At the root of each filesystem I find a structure /.Trash-1000 containing expunged, files and info subdirectories. 1000 is my user ID. If I "delete" a file on the /quitelarge filesystem it disappears to the .Trash-1000/files directory on the quitelarge filesystem. This makes sense as there is no reason to copy the deleted file to the trash folder on the fllesystem where my home resides. All of this seems to be working OK.
Incidentally, I've got the same kind of set-up with a bigstuff & video (separate partitions).
bigstuff just tells me (words to the effect) that it can't preserve an attempted deletion, do I want do delete anyway.
But video works fine and moves the file into its Trash.
I don't know why this is so - I'm guessing it's probably a permissions/ownership thing?
This is not a problem for me, so I've never bothered about it.
A search for "Trash directories on removable media" on LinuxQuestions.org returned two threads. This one and another where the user wanted to prevent Ubuntu from creating one. A www wide search brought up a lot of hits about how does trash work, not work, I want it, I don't want it etc. That is NOT the issue. I understand how the trash folder process works. My system properly creates various trash directory structures per the XDG specs referenced (as best I can determine.)
The issue is that CentOS/Mate "remembers" trash is present even when the file system containing the Trash folder is removed and/or unmounted from the system. This included removable media, encrypted "containers" (e.g. VeraCrypt) and LUKS encrypted Linux file systems. I say it remembers in that the trash icon shows trash present even though it cannot be accessed nor deleted. Ubumtu Mate seems to handle it in a more rational manner at least as far as removable devices. I have not tried an encrypted container or file system on Ubuntu.
I did determine that a logout/login will cause this remembrance to clear. It sure sounds like a bug in whatever manages the state of the trash icon to me.
If the option is available, I set file managers to bypass Trash and just make the file go away. If I blow away the wrong file, it's on me.
In KDE's Konqueror in file manager mode, "direct delete" is a configuration option (I forget the exact wording). In KDE's Dolphin, you can set "Trash" to delete files from Trash after [unit] time. I don't use other file managers enough to know whether they offer such options, but it might be worth exploring them.
I generally use gnome-commander. Delete means DELETE. I also have the option set in Caja (Mate fork of Nautilus) to bypass trash. Where I generally run across the issue is with Eye of Mate (Eye of Gnome) when culling photos. I see one I don't like and press the delete key forgetting that it does not "delete."
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.