-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Welcome to the rmfd wiki!
rmfd is a fork of GNU coreutils’ rm command, which adds a —warnings (-w) option. From the README file:
These are the rmfd files.
rmfd is a fork of rm from GNU Coreutils version 8.5. It has been forked to add the new option --warnings (short name -w). This option reads a list of path names from $HOME/.rmfd/warn.list and warns the user if the rmfd invocation will result in the removal of any of those files. The user is issued a prompt to continue, and if the user declines, nothing is removed (there is an inherent race condition, so once it starts removing files, it will still check the list and never remove a file without prompting, but at that point it can't restore the files that were already deleted).
It attempts intelligent handling of symbolic links. If a symbolic link is put in the list, rmfd will warn if either the link or the target of the link is going to be deleted. If a directory is found in the list, it will furthermore warn if a recursive removal of the directories contents are attempted through a symbolic link.
It attempts to catch mistakes with globs. If a directory D is in the list, it will do its best to discern when `cd D ; rm *' or `rm D/*' is being invoked, and will warn and prompt for whether to continue.
When stderr is attached to a terminal it uses color (bright red) for warnings to be sure they are not mistaken for normal output.
Other than that, and without the --warnings option, rmfd behaves identically to rm. It is meant to be a drop-in replacement for /bin/rm.
Here are some examples:
$ cd /tmp $ echo /tmp/d/b > ~/.rmfd/warn.list $ mkdir d $ touch d/{a,b,c} $ rm -rw d rm: WARNING: you are about to remove `/tmp/d/b'; continue? n $ ls d a b c $ echo /tmp/d > ~/.rmfd/warn.list $ cd d $ rm * rm: WARNING: you are about to remove 3 files via `/tmp/d/*'; continue? n $ cd .. $ rm d/* rm: WARNING: you are about to remove 3 files via `/tmp/d/*'; continue? n $ ln -s d e $ rm -rw e rm: WARNING: you are about to recursively remove the contents of `/tmp/d' through symbolic link `e'; continue? n $ rm e $ rm -rw d rm: WARNING: you are about to remove `/tmp/d'; continue? y $ ls d e ls: cannot access d: No such file or directory ls: cannot access e: No such file or directory $ rm ~/.rmfd/warn.list ; touch d ; rm -w d && ls d ls: cannot access d: No such file or directory
The --warnings option overrides the --force option, so it's simple to alias rm to 'rm -w' and use it as you always would.
First, rmfd is not a substitute for proper system backup and being plain ol’ careful. It is intended as a better-than-nothing system designed to catch mistakes before you have to waste an hour or two restoring half your files. That said, it does quite a bit to help, and tries to do it in an accurate and correct a manner as possible. Some things (like detecting glob expansions) can’t be done perfectly, but in the spirit of Coreutils from which it forked, it makes every attempt to function robustly.
For more complete documentation, see the man page after building.
The only other similar tool I’ve seen is safe-rm. Here are some differences between the two:
rmfd | safe-rm |
---|---|
Replaces the standard rm | Wraps the standard rm |
Written in C | Written in perl |
Protects files and directories in the blacklist even if they would be removed via recursion | Checks only files given on the command line |
The user is prompted before any files are removed and given an opportunity to abort the entire operation when warned | Blacklisted files are skipped, others are removed |
Only allows absolute path names in the warnings list | Allows globs |
Breaks POSIX compatibility (specifically, when given the -f option, rm is never supposed to prompt) |
Removes arguments from the argument list, so it can fail when all arguments are removed (I’m not sure what POSIX says about this) |
Handles symbolic links intelligently | Symbolic links can always be removed |
Includes an automated test suite | Manual tests are run before release |
Attempts to detect glob expansion in protected directories | |
Only consults a user-specified list | Consults a system-wide list to which users can append their own list |
Safe-rm comes with a hard-coded default list included here in case you want to use it:
/bin
/boot
/dev
/etc
/home
/initrd
/lib
/proc
/root
/sbin
/sys
/usr
/usr/bin
/usr/include
/usr/lib
/usr/local
/usr/local/bin
/usr/local/include
/usr/local/sbin
/usr/local/share
/usr/sbin
/usr/share
/usr/src
/var