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 foo
Restore multiple trashed files seperated by ',', also support range:
$ 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 What file to restore [0..3]: 0-2, 3 $ ls foo bar bar2 foo2 foo bar bar2 foo2
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.
Steps
sudo mkdir --parent /.Trash sudo chmod a+rw /.Trash sudo chmod +t /.Trash
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.
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.
File trashed from the home partition will be moved here:
~/.local/share/Trash/
Requirements:
- Python 3 (Python 2.7 may work)
- pip (use apt-get install python-pip on Debian)
Installation command:
pip install trash-cli
System-wide installation:
git clone https://github.com/andreafrancia/trash-cli.git cd trash-cli sudo pip install .
User-only installation:
git clone https://github.com/andreafrancia/trash-cli.git cd trash-cli pip install .
After the user installation you may want add this line to your .bashrc:
export PATH=~/.local/bin:"$PATH"
For uninstalling use:
pip uninstall trash-cli
Debian/Ubuntu (apt):
sudo apt install trash-cli
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.
Environment setup:
virtualenv env --no-site-packages source env/bin/activate pip install -r requirements-dev.txt -r requirements.txt
Running tests:
pytest unit_tests # run only unit tests pytest integration_tests # run all integration tests pytest # run all tests
Check the installation process before release:
python check_release_installation.py