1

I am using Ubuntu in Win10, but I can not find the trash folder, even when I use the command

mv ~/.Trash/foo ~/
mv: cannot stat '/home/man/.Trash/foo': No such file or directory

My question is that how can I open trash folder in Ubuntu/Win10?

Dan
  • 13,119
ABCDEMMM
  • 325

3 Answers3

10

Trash is located in ~/.local/share/Trash, at least in Ubuntu. ~/.local – or more precisely, ~/.local/share – is where XDG-compliant programs store user data (e.g., fonts, mail messages) according to the XDG Base Directory specification.

Ubuntu on WSL only provides you with a terminal and no GUI by default.

Whenever a file is deleted from a graphical file manager in Ubuntu like Nautilus or Thunar, they are actually moved into ~/.local/share/Trash. Files are usually deleted using rm from the terminal, which doesn't move them to the Trash folder.

So there is no trash folder in WSL unless you use a Linux graphical file manager.

DaVince
  • 234
Kulfy
  • 17,696
  • 1
    It is a falsehood that graphical user interfaces do not exist in the WSFL. https://askubuntu.com/questions/808474/ It is a falsehood that .local is tied to graphical user interfaces. – JdeBP Oct 25 '18 at 10:57
  • At least as of WSL under Ubuntu 20.04 the trash is in the usual location ~/.local/share/Trash. – wardw May 03 '20 at 12:04
3

My WSL (Ubuntu-20.04) didn't have a ~/.local/share/Trash folder. I followed the instructions here (https://github.com/sindresorhus/trash) and installed trash and trash-cli with npm.

Things like these work now!

[username@host]$ tldr trash
trash
A CLI for managing your trashcan / recycling bin.More information: https://github.com/andreafrancia/trash-cli.
  • Delete a file (send to trash): trash {{path/to/file}}

  • List files in trash: trash-list

  • Restore file from trash: trash-restore

  • Empty trash: trash-empty

  • Empty trash, keeping files trashed less than {{10}} days ago: trash-empty {{10}}

  • Remove all files named 'foo' from the trash: trash-rm foo

  • Remove all files with a given original location: trash-rm {{/absolute/path/to/file_or_directory}}

Tip: https://github.com/tldr-pages/tldr is a really cool tool to get practical examples of commands that manual pages usually don't have.

1

The Trash folder in Ubuntu is typically provided by gio (Gnome IO) and GVfs (the Gnome Virtual Filesystem). While applications like Nautilus act on the GVfs to access the trash, it can also be done directly from the command-line on WSL or Ubuntu Server, without any GUI, using the gio commandline tool.

It does, however, require a D-Bus user session, which does not run automatically under WSL since there's (a) no Systemd and (b) no concept of "login" during which to start user services.

While gio and D-bus are both installed by default in the WSL Ubuntu distribution, you do need to add the gvfs package (at least on WSL):

sudo apt install gvfs

Then you need to launch your shell with D-Bus support. This can be done multiple ways, but perhaps the best option is to change your WSL launch command (in Windows Terminal or elsewhere) to:

wsl ~ -e dbus-launch bash # Or your preferred shell

At this point, you can use the Trash from the WSL command line. Example:

touch "a test file"
gio trash "a test file"
gio list Trash://
ls -lah ~/.local/share/Trash/files
gio trash --empty
gio list Trash://
ls -lah ~/.local/share/Trash/files
NotTheDr01ds
  • 17,888