Linux: Move File to Trash by Command
What is the Linux command to move file to trash?
gvfs-trash filepath
This works in all {Ubuntu, Gnome, Xfce, KDE}.
Where is the trash directory?
~/.local/share/Trash/
- On your local file system.
/root/.local/share/Trash/
- If you are root, on your local file system.
/media/PENDRIVE/.Trash-1000/
- On a USB drive.
It is safe to delete the trash directory.
rm -r ~/.local/share/Trash
How Does Linux Trash Work?
In the trash dir, there are 3 dirs:
expunged
- Deleted files but for some reason unable to delete. (this is not in spec, as of version 0.7.)
files
- Contains the actual trashed files.
info
- Contains text file that has info about trashed file.
For example, if you have a file at /home/joe/Downloads/cat.jpg
and you deleted to trash. Then, you'll have:
~/.local/share/Trash/files/cat.jpg
~/.local/share/Trash/info/cat.jpg.trashinfo
and the file cat.jpg.trashinfo
will have content like this:
[Trash Info] Path=/home/joe/Downloads/cat.jpg DeletionDate=2013-05-29T00:09:26
Reference
〔The FreeDesktop.org Trash specification By Mikhail Ramendik. At http://www.ramendik.ru/docs/trashspec.html〕