Is there a simple way to evaluate what a given rm command will do when you do not understand it (such as not recognizing how the flags, variables, etc. interact)?While ls helps catch problems in your rm parameters, ls -abc XYZ does not list the same files that would be affected by rm -abc XYZ. Ideally, I would like to type something like previewrm -abc XYZ and see what would be removed without actually removing anything, including using the -f flag.I essentially want to run rm in test batch mode. That is, I want to see what actions it would take if it was run for real, preferably without touching it at all. Thus, testout 'rm -abc XYZ' might be the true ideal.
Is there a simple way to preview the files that rm will remove?
rm
The simple way is to use rm -i the way @orion describes. If you want something that will not remove anything but doesn't tweak rm's flags, you can always build your own version of rm, let's call it preview-rm. It's really pretty straightforward, and you can even do it without touching the actual rm source files:Find the source to your system's version of rm. You may need to download a source package, or whatever. GNU rm is part of the core utilities and consists of two C files, rm.c and remove.c, and several header files. Once you are set up to compile system utilities, the rest is trivial.Create the file mockrm.c with the following contents. The only non-trivial part is that some versions of rm detect directories by trying to unlink() them and checking for error, so we need to ensure this works correctly:#include <stdio.h>#include <sys/stat.h>#include <errno.h>int unlink(char *s){    struct stat sbuf;    lstat(s, &sbuf);    /* Simulate unlink error if we're asked to unlink a directory. */    if (S_ISDIR(sbuf.st_mode)) {        return EISDIR;    }    puts(s);    return 0;}    int rmdir(char *d){  printf(%s (dir)\n, d);  return 0;}Finally, compile your preview-rm executable like this:% cc rm.c remove.c mockrm.c -o preview-rmThe functions in mockrm.c will be linked in precedence to the system calls provided by the C library, giving you a toothless clone of rm that you can use for preview. (Do test that it really works before you point it at important files.)Alternative: If you're on a system that supports the LD_PRELOAD feature (OS X doesn't), you might be able to get the same effect by compiling mockrm.c into a shared library (.so) and forcing it to be loaded by the real rm:% LD_PRELOAD=/path/to/mockrm.so rm -flags filesBut since you need to change the command invocation anyway, why not just create a separate executable as shown above. I know it'd be a little nervous pointing the real rm at valuable files (Edit: and if you update your OS, you'd have to test again and make sure rm hasn't changed in a way that disabled the wrapper.)