Here you can find the mv_safe script that tracks operations' history, allowing you to easily revert them with the undo script.
The mv_safe file uses the mv with -b and -i options, which means it asks you before overwriting a file, and creates a backup for it.
It has almost all the functionalities the standard mv command has, including:
- renaming a file or directory,
- overwrtiting a file,
- moving a file or directory into another directory.
To use the script, copy the mv_safe file to a directory included in your $PATH, for example:
cp mv_safe ~/bin/
chmod +x ~/bin/mv_safeI recommend setting an alias to replace the default mv command with mv_safe:
alias mv='mv_safe'Add this line to your ~/.bashrc or ~/.zshrc file, and then run:
source ~/.bashrc # (or ~/.zshrc)My initial plan was to write the undo script both for mv and rm. However, this would not be necessary - since there is a gio trash command that already provides such functionality.
To make the rm command move files into trash instead of deleting them permamently, you can create an alias:
alias rm='gio trash'