Ubuntu/Windows (WSL) 中的「垃圾箱」資料夾在哪裡?

Ubuntu/Windows (WSL) 中的「垃圾箱」資料夾在哪裡?

我在用Win10 中的 Ubuntu,但即使我使用命令,我也找不到垃圾資料夾

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

我的問題是如何在 Ubuntu/Win10 中開啟垃圾資料夾?

答案1

垃圾位於~/.local/share/Trash,至少在 Ubuntu 中是如此。~/.local– 或者更準確地說,~/.local/share– 是 XDG 相容程式根據以下方式儲存使用者資料(例如字體、郵件訊息)的位置:XDG 基本目錄規範

WSL 上的 Ubuntu 只為您提供預設沒有終端和 GUI

每當從 Ubuntu 中的圖形檔案管理器(如 Nautilus 或 Thunar)中刪除檔案時,它們實際上會被移至~/.local/share/Trash.文件通常是rm從終端刪除的,移動將它們放入垃圾箱文件夾

因此,除非您使用 Linux 圖形檔案管理器,否則 WSL 中沒有垃圾資料夾。

答案2

我的 WSL (Ubuntu-20.04) 沒有 ~/.local/share/Trash 資料夾。我按照這裡的說明進行操作(https://github.com/sindresorhus/trash)並安裝 trashtrash-cli使用npm.

像這樣的事情現在就可以了!

[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}}

提示:https://github.com/tldr-pages/tldr是一個非常酷的工具,可以獲取手冊頁通常沒有的命令的實際範例。

答案3

gioUbuntu 中的「垃圾箱」資料夾通常由(Gnome IO) 和 GVfs(Gnome 虛擬檔案系統)提供。雖然像 Nautilus 這樣的應用程式作用於 GVfs 來存取垃圾,但也可以使用命令列工具直接從 WSL 或 Ubuntu Server 上的命令列完成,無需任何 GUI gio

但是,需要 D-Bus 使用者會話,該會話不會在 WSL 下自動執行,因為 (a) 沒有 Systemd,且 (b) 沒有啟動使用者服務的「登入」概念。

雖然gioWSL Ubuntu 發行版中預設安裝了 D-bus 和 D-bus,但您確實需要添加該gvfs軟體包(至少在 WSL 上):

sudo apt install gvfs

然後您需要啟動具有 D-Bus 支援的 shell。這可以透過多種方式完成,但也許最好的選擇是將 WSL 啟動命令(在 Windows 終端機或其他地方)更改為:

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

此時,您可以從 WSL 命令列使用垃圾箱。例子:

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

相關內容