Linux: Move File to Trash by Command

By Xah Lee. Date: . Last updated: .

What is the Linux command to move file to trash?

gvfs-trash filepath

This works in all {Ubuntu, Gnome, Xfce, KDE}.

[see Linux: How to Switch to LXDE, Xfce]

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:

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]

Linux Shell Basics

Sys Admin

Bash/Terminal

Linux Desktop