Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Command line interface to FreeDesktop.org Trash.

Project Description

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.

Usage

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
foo

Remove all files from the trashcan:

$ trash-empty

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

$ trash-empty <days>

Example:

$ 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.

FAQ

How to create a top level .Trash dir?

Steps

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 rhe 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.

Installation

The easy way

Requirements:

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

Installation command:

easy_install trash-cli

From sources

System-wide installation:

git clone https://github.com/andreafrancia/trash-cli.git
cd trash-cli
sudo python setup.py install

User-only installation:

git clone https://github.com/andreafrancia/trash-cli.git
cd trash-cli
python setup.py install --user

Bugs and feedback

If you discover a bug please report it here:

https://github.com/andreafrancia/trash-cli/issues

You can also email me to andrea@andreafrancia.it. On Twitter I’m @andreafrancia.

Development

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:

python check_release_installation.py

Profiling unit tests:

pip install gprof2dot
nosetests --with-profile --profile-stats-file stats.pf --profile-restrict=unit_tests unit_tests
gprof2dot -w  -f pstats stats.pf | dot -Tsvg >| stats.svg
open stats.svg
Release History

Release History

This version
History Node

0.17.1.14

History Node

0.17.1.12

History Node

0.17.1.1

History Node

0.16.12.29

History Node

0.16.12.28

History Node

0.16.12.26

History Node

0.16.12.25

History Node

0.12.9.14

History Node

0.12.7

History Node

0.12.6

History Node

0.12.4.24

History Node

0.12.4

History Node

0.11.3-r315

History Node

0.11.2

History Node

0.11.1.2

History Node

0.11.0

History Node

0.11.0.dev-r215

History Node

0.11.0.dev-r199

History Node

0.2.1.dev-r192

History Node

0.2.1.dev-r191

History Node

0.2.1.dev-r190

History Node

0.2.1.dev-r184

History Node

0.2.1.dev-r168

History Node

0.2.1.dev-r160

History Node

0.2.1.dev-r157

History Node

0.2.1.dev-r153

History Node

0.2.1.dev-r143

History Node

0.2.1.dev-r142

History Node

0.2.1.dev-r141

History Node

0.2.1.dev-r129

History Node

0.2.1.dev-r82

History Node

0.2.1.dev-r81

History Node

0.2.1.dev-r79

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
trash-cli-0.17.1.14.tar.gz (20.7 kB) Copy SHA256 Checksum SHA256 Source Jan 14, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting