Package: careful_rm
Version: 1.0-beta10A wrapper for rm that adds more useful warnings and an optional recycle/trash
modeCan be used as a drop-in replacement forrmon any Linux or MacOS system with
Python > 2.6. With no arguments or configuration, it will warn you if you delete
more than 3 files or any directories, and will print the files and folders to
delete to the console when prompting for approval (somethingrm-Idoes not
do).Allrmcommands are implemented here. In addition, passing-cwill result in
files being trashed/recycled instead of deleted. Applescript is used on MacOS,
otherwise the best trash location is chosen (see below). Most files can be
restored using GUI tools (e.g. Nautilus/Finder), as the default Trash folders
and metadata are used (e.g.Put Backworks on Mac).Note: passing-swill result in files being destroyed withshredand will
forcibly override and disable recycle mode.Ideally, this tool should be symlinked tormand the file~/.rm_recycle_homeshould be created, which will make recycling automatic only for files in your
home directory. This will provide a great deal of safety without majorly messing
up any sys-admin work.ContentsUsageInstall as a pluginRequirementsGeneral InstallZSHAntigenOh-My-ZSHZgenInstall Script OnlyVia PIPDirect InstallRationale and ImplementationUsageUsage: careful_rm.py [-c] [-f | -i] [-dPRrvW] file ..

Arguments
---------
    -c, --recycle         move to trash instead of deleting (forced on by
                          ~/.rm_recycle)
    -s, --shred           run shred on all files (recursively if directories
                          included) prior to deleting, override recycle
        --direct          force off recycling, even if ~/.rm_recycle exists
        --dryrun          do not actually remove or move files, just print
    -h, --help            display this help and exit

All other arguments passed to rm

Common rm arguments
-------------------
    -f, --force           ignore nonexistent files and arguments, never prompt
    -i                    prompt before every removal
    -I                    prompt once before removing more than three files, or
                          when removing recursively
    -r, -R, --recursive   remove directories and their contents recursively
    -d, --dir             remove empty directories
    -v, --verbose         explain what is being done

For full help for rm, see `man rm`, note that only the '-i', '-f' and '-v'
options have any meaning in recycle mode, which uses `mv`. Argument order does
not matter.Install as a pluginRequirementsAnshstyle shell, preferablyzsh,dash, orbashPython version 2.6+, no additional modules requiredIt should work almost everywhereNote: If anyone can help with a FISH and/or Windows version, that would be greatGeneral InstallWith anyshlike shell (sh,bash,fish,zsh)cd ~git clone git@github.com:MikeDacre/careful_rm.gitecho "source ~/careful_rm/careful_rm.alias.sh" >> .bashrcZSHThe ZSH version of this plugin is provided by thecareful_rm.plugin.zshfile.
In addition to aliasingrmtocareful_rm, it also sets a$TRASHvariable
that updates with every directory change and makes~trasha named directory
that points to$TRASH.ZSH offers some great ways to install as a plugin and stay up to date, my
favorite is antigen, but any of the following methods will work.AntigenIf you’re usingAntigen, just addantigen bundle MikeDacre/careful_rmto your.zshrcfile where you’re loading your
other zsh plugins. You will need to reload ZSH to install the plugin.Oh-My-ZSHmkdir-p~/oh-my-zsh/custom/pluginscd~/oh-my-zsh/custom/pluginsgit clone git@github.com:MikeDacre/careful_rm.gitaddplugins+=(careful_rm)to the right place in your~/.zshrcZgenIf you’re usingZgen, addzgen load MikeDacre/careful_rmto your.zshrcfile where you’re loading your other zsh
plugins.Install Script OnlyIf you want you can install the code directly and handle shell integration
yourself. The project can be installed with either pip, or just by directly
downloading the script.To alias the code to rm yourself, you can download and source thecareful_rm.alias.shscript, or just add something like this to your~/.bashrc.ifhashcareful_rm.py2>/dev/null;thenaliasrm="$(command-vcareful_rm.py)"elifhashcareful_rm2>/dev/null;thenaliasrm="$(command-vcareful_rm)"elsealiasrm="rm -I"fiVia PIPThis project is onPyPIso you can just install it
withpip, but youwon’t get any shell integration:pipinstallcareful_rmDirect InstallYou can just put it into your$PATHand use it directly. e.g.:cd /usr/local/binwgethttps://raw.githubusercontent.com/MikeDacre/careful_rm/master/careful_rm.pyRationale and Implementationrmis a powerful *nix tool that simply drops a file from the drive index. It
doesn’t delete it or put it in a Trash can, it just de-indexes it which makes
the file hard to recover unless you want to put in the work, and pretty easy to
recover if you are willing to spend a few hours trying (useshredto actually
secure erase files).careful_rm.pyis inspired by the-Iinteractive mode ofrmand bysafe-rm.safe-rmadds a recycle
bin mode to rm, and the-Iinteractive mode adds a prompt if you delete more
than a handful of files or recursively delete a directory.ZSHalso has an
option to warn you if you recursively rm a directory.These are all great, but I found them unsatisfying. What I want is for rm to be
quick and not bother me for single file deletions (sorm-iis out), but to
let me know when I am deleting a lot of files, andto actually print a list of
files that are about to be deleted. I also want it to have the option to
trash/recycle my files instead of just straight deleting them…. likesafe-rm, but not so intrusive (safe-rm defaults to recycle, and doesn’t warn).careful_rm.pyis fundamentally a simplermwrapper, that accepts all of the
same commands asrm, but with a few additional options features. In the source
codeCUTOFFis set to3, so deleting more files than that will prompt the
user. Also, deleting a directory will prompt the user separately with a count of
all files and subdirectories within the folders to be deleted.Furthermore,careful_rm.pyimplements a fully integrated trash mode that can
be toggled on with-c. It can also be forced on by adding a file at~/.rm_recycle, or toggled on only for$HOME(the best idea), by~/.rm_recycle_home. The mode can be disabled on the fly by passing--direct,
which forces off recycle mode.The recycle mode tries to find the best location to recycle to on MacOS or
Linux, on MacOS it also tries to use Apple Script to trash files, which means
the original location is preserved (note Applescript can be slow, you can
disable it by adding a~/.no_apple_rmfile, butPut Backwon’t work). Thebestlocation for trashes goes in this order:$HOME/.Trashon Mac or$HOME/.local/share/Trashon Linux<mountpoint>/.Trasheson Mac or<mountpoint>/.Trash-$UIDon Linux/tmp/$USER_trashAlways the best trash can to avoid Volume hopping is favored, as moving across
file systems is slow. If the trash does not exist, the user is prompted to
create it, they then also have the option to fall back to the root trash
(/tmp/$USER_trash) or justrmthe files./tmp/$USER_trashis almost always used for deleting system/root files, butnotethat you most likely do not want to save those files, and straightrmis generally better.