Trash - Command line trash can.


Trash [--] FILE(s) : trash files
Trash : list contents of trash
Trash -l | -s : list contents of trash and file sizes
Trash -r FILE(s) : recover files to current directory
Trash -r DIR/FILE : recover single file to directory DIR
Trash -e : empty trash can


Trash is a command line trash can, by default configured to work with the generic trash-can $HOME/.Trash.

AFAIK Trash can handle all unusual filenames.

Trash -l will list the sizes of all trashed files/directories, and sort output.

Trash -r DIR/FILE is a convenience feature to restore a single file to the directory it came from. Mistakenly Trashing a file in another directory would otherwise necessitate: Trash -r FILE ; mv FILE DIR.

Users of KDE >= 3.4 may wish to use the KTrash utility, which has a proper path restore feature.


Configuration can be done in two ways:

1. edit the beginning of the Trash shell script, or preferably
2. copy the beginning of the script into the file ~/.Trashrc

There are two variables that need to be set:

"TRASH" is the directory.
"EXCLUDE" is a regexp of files that are never deleted from TRASH.

Files (except ".") must be prefixed with "./" , and separated by "|".
Special characters (including "." and "|") must be prefixed with a backslash "/".

In summary, for KDE<3.4: EXCLUDE="\./\.directory\|\." TRASH=${HOME}/Desktop/Trash

for Gnome : EXCLUDE="\."


Trash will backup files of the same name by appending ~1~, and shuffling subsequent files to ~2~, ~3~ ...
This means that for files of the same name, the larger the number, the longer it has been in the Trash.

Trash has a safety feature. If the first arg is "mv", Trash will exit. To Trash a file named "mv" use "Trash -- mv".


Trash -r "a b" doesn’t work.
(Trash -r "a*" does)

See Also



Steven Atkinson (stevenaaus (at) yahoo (dot) com)