Skip to content
Command line interface to the trashcan.
Branch: master
Clone or download
andreafrancia Merge pull request #100 from yssmcl/patch-2
Change 'rhe' for 'the' in README.rst
Latest commit 5abecd5 Aug 16, 2017
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Update upstream URL for safe-rm Jan 1, 2014
man/man1 Add a reference to trash-rm(1) to all man pges Dec 31, 2016
tasks Fix mkdir option in tasks/make-disk.osx Jan 4, 2017
trashcli Refactor Jan 25, 2017
unit_tests Refactor: now also 'now' is injected Jan 25, 2017
CREDITS.txt Add credit for Lee Yeoh Jan 19, 2017
HISTORY.txt Update HISTORY.txt Jan 22, 2017 fixed inclusion of README.rst when creating distribution package Jun 21, 2012
README.rst Update README.rst Aug 15, 2017
TODO.txt Clean TODO.txt Dec 31, 2016
Vagrantfile Switch to ubuntu/yakkety64 that is supposed to present bug #52 (crash… Dec 26, 2016
bugs.txt Some refactors Aug 12, 2012 Add check for easy_install3 installation Jan 13, 2017
requirements-dev.txt Remove dependency from dingus and fudge. Apr 12, 2012
setup.cfg Fix python3 incompatibility found in using file instead of … Jan 6, 2017
trash-put Add integration test for the whole trash-put script Jan 24, 2017
trash-rm Now the integration test use the generated trash-rm script, and the g… Jan 24, 2017


trash-cli - Command Line Interface to Trash.


trash-cli trashes files recording the original path, deletion date, and permissions. It uses the same trashcan used by KDE, GNOME, and XFCE, but you can invoke it from the command line (and scripts).

It provides these commands:

trash-put           trash files and directories.
trash-empty         empty the trashcan(s).
trash-list          list trashed files.
trash-restore       restore a trashed file.
trash-rm            remove individual files from the trashcan.


Trash a file:

$ trash-put foo

List trashed files:

$ trash-list
2008-06-01 10:30:48 /home/andrea/bar
2008-06-02 21:50:41 /home/andrea/bar
2008-06-23 21:50:49 /home/andrea/foo

Search for a file in the trashcan:

$ trash-list | grep foo
2007-08-30 12:36:00 /home/andrea/foo
2007-08-30 12:39:41 /home/andrea/foo

Restore a trashed file:

$ trash-restore
0 2007-08-30 12:36:00 /home/andrea/foo
1 2007-08-30 12:39:41 /home/andrea/bar
2 2007-08-30 12:39:41 /home/andrea/bar2
3 2007-08-30 12:39:41 /home/andrea/foo2
4 2007-08-30 12:39:41 /home/andrea/foo
What file to restore [0..4]: 4
$ ls foo

Remove all files from the trashcan:

$ trash-empty

Remove only the files that have been deleted more than <days> ago:

$ trash-empty <days>


$ date
Tue Feb 19 20:26:52 CET 2008
$ trash-list
2008-02-19 20:11:34 /home/einar/today
2008-02-18 20:11:34 /home/einar/yesterday
2008-02-10 20:11:34 /home/einar/last_week
$ trash-empty 7
$ trash-list
2008-02-19 20:11:34 /home/einar/today
2008-02-18 20:11:34 /home/einar/yesterday
$ trash-empty 1
$ trash-list
2008-02-19 20:11:34 /home/einar/today

Remove only files matching a pattern:

$ trash-rm \*.o

Note: you need to use quotes in order to protect the pattern from shell expansion.


How to create a top level .Trash dir?


sudo mkdir --parent /.Trash
sudo chmod a+rw /.Trash
sudo chmod +t /.Trash

Can I alias rm to trash-put?

You can but you shouldn't. In the early days I thought it was a good idea to do that but now I changed my mind.

Although the interface of trash-put seems to be compatible with rm, it has different semantics which will cause you problems. For example, while rm requires -R for deleting directories trash-put does not.

But sometimes I forget to use trash-put, really can't I?

You could alias rm to something that will remind you to not use it:

alias rm='echo "This is not the command you are looking for."; false'

Then, if you really want to use rm, simply prepend a slash to bypass the alias:

\rm file-without-hope

Note that Bash aliases are used only in interactive shells, so using this alias should not interfere with scripts that expect to use rm.


The easy way


  • Python 2.7 or Python 3
  • setuptools (use apt-get install python-setuptools on Debian)

Installation command:

easy_install trash-cli

From sources

System-wide installation:

git clone
cd trash-cli
sudo python install

User-only installation:

git clone
cd trash-cli
python install --user

Bugs and feedback

If you discover a bug please report it here:

You can also email me to On Twitter I'm @andreafrancia.


Environment setup:

virtualenv env --no-site-packages
source env/bin/activate
pip install -r requirements-dev.txt

Running tests:

nosetests unit_tests           # run only unit tests
nosetests integration_tests    # run all integration tests
nosetests -A 'not stress_test' # run all tests but stress tests
nosetests                      # run all tests

Check the installation process before release:


Profiling unit tests:

pip install gprof2dot
nosetests --with-profile --profile-stats-file --profile-restrict=unit_tests unit_tests
gprof2dot -w  -f pstats | dot -Tsvg >| stats.svg
open stats.svg
You can’t perform that action at this time.