$ rm --help
===============
This is a modified rm program to move SRC to RM_ALT_TRASH instead of remove it.
Usage:
rm-alternative.bash [OPTION]... SRC [SRC]...
Options:
-h, --help
-n, --dry-run
-d, --delete ---- `rm -rf SRC` is executed using `/bin/rm` (Be careful!!!)
--restore ---- Restore previously moved files to their original locations.
Previously moved history is saved in RM_ALT_HIST
Default values:
RM_ALT_TRASH = ~/.myTrash
RM_ALT_HIST = $RM_ALT_TRASH/.moved_hist
- When
rm SRC
is executed,SRC
is moved to~/.myTrash
- If there is another
SRC
with the same name in~/.myTrash/
, the older one will be renamed as SRC-DATE
- If there is another
rm [-d/--delete] SRC
invokes the system command:/bin/rm -rf SRC
- With
-n/---dry-run
option, no files will be moved, only what will be done will be displayed - If you run
rm
by mistake, you can undo by runningrm -restore
- Clone this repository
git clone https://github.com/naoking158/rm-alternative.git
- Set alias in
.bashrc
,.zshrc
, etc…alias rm='/path/to/rm-alternative.bash'
Add execute permission to
rm-alternative.bash
as likechmod +x rm-alternative.bash
if necessary. - Option: By setting
sudo
as an alias, commands registered in the alias can be invoked withsudo
alias sudo='sudo '
Note that it is important to leave a space after sudo.
See
man bash
for more detail.If the last character of the alias value is a blank, then the next command word following the alias is also checked for alias expansion.
To change the trash directory and the history file, set RM_ALT_TRASH
and RM_ALT_HIST
as environment variables in .profile
, .bashrc
, .zshrc
, etc…
export RM_ALT_TRASH="/path/to/trash"
export RM_ALT_HIST="${RM_ALT_HIST}/filename_as_you_like"