0

I want to restore I file I deleted accidentally. I cannot go to the trash/wastebasket folder and simply restore the file, because I've no idea what the file was. I deleted it by accidentally pressing the delete key while the screen focus was on a Thunar window. (This is a particular hazard when you have a mechanical keyboard and human fingers).

Thunar does not show deleted dates, so it is not possible to simply sort the files in the trash/wastebasket folder.

But if I right-click on a deleted file in the wastebasket, and look at files properties, I see that files in the wastebasket do have a "Deleted" date property.

How do I list the files by deleted date in a terminal. And how do I open the wastebasket folder in a terminal?

And if the wastebasket folder is virtual, and the file properties given a deleted date stored in some other place, where is that place and how do I query it? (I see that if I look in ~/.local/share/Trash/files/, it looks like the same files as are in the wastebasket that you navigate to from the Thunar side-panel icon. But the files in ~/.local/share/Trash/files/ do not have "Deleted" date as an attribute when you right-click to see their properties).

1 Answer 1

2

If you open Trash with Thunar, you can sort the files by "Date Modified", which is the mtime of the file while it was alive. So you can't tell what was last deleted, in case you keep a lot of files into there.

But when the file is deleted, or better moved to Trash, the ctime changes. So sorting them by ctime could help you:

find ~/.local/share/Trash/files/ -type f -printf '%C+ %f\0' |
    sort -rz | tr '\0' '\n' | head

The output is sorted by change time, meaning by deletion time, the last deleted file is first into this output. Then you can select its filename into Thunar and restore it.


Also, the files into Trash/files are regular files (for any regular file you have deleted), think that when you press delete into Thunar (without the shift key) a mv happens instead of an rm. And into Trash/info you can see that there is a *.trashinfo file, containing the path (for the case of restoration) and the Deletion Date. We could also parse this info to find the latest one. Or just sort the *.trashinfo files by mtime.

For example, to print newer entries first:

cd ~/.local/share/Trash/info
ls -lt *.trashinfo
4
  • Aha - .trashinfo. I missed that signpost! Moving to trash changes a file's inode??? That's ctime, right? I found grep "2022-05-24" *, for example, in the trash/info dir, gave nice. (The only problem is, bizarrely, that by the times I find in my Trash dir now, I seem not to have deleted any files for the last week and a half! I'm baffled).
    – markling
    May 25, 2022 at 18:01
  • There is no other place you could find files deleted into Thunar. Could it be a different action that happened. Also take care to adjust your settings regarding windows focus and similar, mistakes are always easier when using a gui than a shell. Also it's good to setup a daily/weekly rsync command to backup useful data.
    – thanasisp
    May 25, 2022 at 20:39
  • Thanks for the tips. The bizarre thing is that, working day and night, as usual, there are no deleted files for the last 10 days in my trash? It is most curious.
    – markling
    May 26, 2022 at 22:48
  • 1
    Do you remember the path where you probably deleted a file accidentally? The files into Trash/files have not their full path, but the Trash/info metadata files have the paths. If yes, you could search by their path (before deletion) also.
    – thanasisp
    May 26, 2022 at 22:51

You must log in to answer this question.

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