How to restore a file from the trash using command line?

Obviously you can use restore-trash command from the trash-cli package, but this wouldn't list all files inside the trash.

Moreover what about files moved to trash with root permission?

Those are files in trash: enter image description here

Now using restore-trash command: enter image description here

only 4 files are shown.

  • "permanently deleted" usually implies you deleted it from trash or skipped trash altogether while deleting. So which is this? – Olorin Aug 12 '17 at 9:51
  • @Olorin Updated to be more clear – Maythux Aug 12 '17 at 10:03
  • 1
    Have you tried running restore-trash using sudo or checking out sudo trash-list are you looking for something else? – Ravexina Aug 12 '17 at 13:14
  • @Ravexina Sure I did... – Maythux Aug 12 '17 at 13:43
  • @Maythux so what was the problem? cause I can list all files (even deleted by root) without sudo, and remove them using sudo... – Ravexina Aug 12 '17 at 13:55

For listing all files in the trash,

ls -l .local/share/Trash/files/

sudo ls -l /root/.local//share/Trash/files/

should do under Ubuntu (in my case: MATE 16.04). I found those paths here. It also has further explanations of what is in the other folders next to files/. In case you want to code your own restore routine, that should help...

Not sure what you are up to (writing tests to verify delete-to-trash?, ...) but looking at the specific source of the trash npm module (js) might give further insight.

| improve this answer | |

If you run trash-restore from within a directory, It will only show the trashed files and directories that were trashed from the current directory or its sub-directories

As it appears, you are running trash-restore from your home directory. So, it is only showing files and directories that were trashed from your home directory or its sub-directories.

To restore files trashed from another directory, for example /var, you would need to cd to the /var directory first and then run trash-restore from there.

Alternatively, you can specify the system root directory / after trash-restore like so trash-restore / to make it show all trashed files and directories originating from anywhere in the system.


The tool is now called trash-restore under the latest trash-cli package.

| improve this answer | |

Each volume has it's own trash. While nautilus or nemo shows the trash combined for all mounted volumes, restore-trash shows only the files from the volume you're currently in, unlike trash-list, which shows the trash for all mounted volumes.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.