You could use rm -i
to be prompted for every single file it will remove. You can pipe no
into it repeatedly, (confusingly) using the yes
command, to just view prompts (rejecting all of them):
yes no | rm -i files/globs/options
EDIT in response to comments by @user63051
If you are concerned about dangerous flag combinations, you can specify
rm -i --
and anything after that will NOT be treated as an option. This of course means that for the -r
flag to work, you need to put it before --
.
Another suggestion, if you want to try it, is to create a dummy
user that doesn't belong to any of the existing groups. If the others
permissions of your files don't include write
permission (they usually don't unless you specifically want that), you can just login as the other user (su dummy
) and do the rm
command. It won't have permissions to delete anything so it will simply complain about it. You can also do this to use the suggestion above (as double protection).
I should warn you that all the options that call rm
are a bit dangerous. I usually just prefix the entire command I want to run with echo
to see what arguments will bash give to the command (how it expands the wildcards and which files it finds). Then just remove echo
if everything looks fine. Notice that this won't list contents of recursively found files with -r
but you will see the directory it wants to destroy.
In essence - use echo
if you want to see what it does. Use --
for protection from runaway flags. Use -i
just in case, it will ask about every file and you will notice if it asks about something you don't want to remove. Only if you really want to produce a list, one file per line, it makes sense to do anything else.
echo rm -abc XYZ
shows you which files and directories will be directly affected. Do you want to see the directory contents? Or do you want to know what cannot be deleted (due to access rights)? – Hauke Laging Mar 18 '14 at 22:19rm $FOO/*
andrm *(1)*
. – Dane Mar 18 '14 at 22:34rm
in test batch mode, i.e. showing what actions it would take if it was run for real (which is what I think you want) then you should say so more explicitly. Two people have suggestedrm -i
, which I don't think does what you want. – Faheem Mitha Mar 18 '14 at 22:35-i
flag are the best I've seen before. I recognize that they might be the best answer there is, but my hope was for something that didn't require touching the flags. While I'm smart enough to pull out the-f
, I'm looking to avoid slip-ups likerm -i -f
. That is, adding the-i
flag is not sufficient; you also have to pull the-f
and--force
. – Dane Mar 18 '14 at 22:39