Remove Command using a trash box.
rm
command removes files/directories from the disk and they are not recoverable.
It is stressful because we are used to benefit from the trash box on a GUI system, Windows, Mac, Linux, etc..
trash
command brings you the removal command with recoverable files/directories.
Please use master version if you wish to the latest version.
On Mac, you can install scripts by Homebrew:
$ brew tap rcmdnk/rcmdnkpac
$ cd $(brew --prefix)/Library/Taps/rcmdnk--rcmdnkpac
$ git checkout d85c945 rcmdnk-trash.rb # use v0.0.2
$ brew install rcmdnk-trash
You can also use an install script on the web like:
$ curl -fsSL https://raw.github.com/rcmdnk/trash/install_sa/install.sh| sh
This will install scripts to /usr/bin
and you may be asked root password.
If you want to install other directory, do like:
$ curl -fsSL https://raw.github.com/rcmdnk/trash/install_sa/install.sh| prefix=~/usr/local/ sh
Or, simply download scripts and set where you like.
# Help
HELP="
Usage: trash [-rficClbv] [-v <verbose level>] [-t <trash_box>] <file/directory>
Arguments:
-r Remove directory (default: $rdir)
-f Remove w/o confirmation (default: $force)
-i Remove w/ confirmation (default: $confirm)
-t <trash_box> Use given trash box instead of $tbox
-c Clean up trash box (make it less than MAXTRASHBOXSIZE)
-C Clean up trash box (make it empty)
-l List up deleted files/directories in the trash box
-b Restore (turn Back) the file from the trash box
-v <level> Verbose level for list view
0 : Only original location (default).
1 : With Delete date-time (yyyymdd-hh:mm).
2 : With Current location (in the trash box).
-h Print this HELP and exit
To use trash, please specify following variables
in .bashrc or your setting file like (these rh values are default):
At restore mode, you can use following keys (based on vim move):
<n> : (any numb), set n for move
j : n-down (if n is not defined, 1 down)
^D : Half page down
^F : Page down
k : n-up (if n is not defined, 1 up)
^U : Half page up
^B : Page up
gg : Go to top (if n is defined, go to n)
G : Go to bottom (if n is defined, go to n)
d : Delete
s : Show details
Enter : Select to bring back to the original place, and quit
h : Select to copy it to current directory, and quit
q : Quit
export TRASHLIST=~/.trashlist # Where trash list is written
export TRASHBOX=~/.Trash # Where trash will be moved in
# (.Trash is Mac's trash box)
export MAXTRASHBOXSIZE=1024 # Max trash box size in MB
# Used for clean up
export MAXTRASHSIZE=\`echo \$MAXTRASHBOXSIZE \"*\" 0.1|bc -l|cut -d. -f1\`
# Trashes larger than MAXTRASHBOXSIZE will be removed by 'rm' directly
"
Following alias is useful to use trash:
alias del="trash -r"
You may be want to clean up trash box regularly to keep the box not too much.
To clean up regularly, first please set MAXTRASHBOXSIZE
as described
in above help.
Then, trash -c
will clean up the trash box until it becomes less than MAXTRASHSIZE
.
You can set it as a cron job like:
0 1 * * * /path/to/trash -c
to execute every night (1am, 00min).
In addition, you can empty your trash box for trash by
$ trash -C