2

I'm not aware of any standard flag that is implemented. There are some git commands that let you specify a -n parameter that will show you what the command is going to do, but doesn't actually do it.

Commands that I'm specifically interested in include rm and mv -- am I out of luck?

2
  • A common problem with scripting is the need to test the script before it is run. However, because scripts typically have a large number of side effects (e.g., network, filesystem, etc.), it is actually quite difficult to test scripts in an isolated environment and examine the side-effects. I'm not aware of any good solution to this problem.
    – jayhendren
    Commented Nov 4, 2014 at 20:49
  • Not really a full answer, but the --simulate and --assume-no flags of apt-get may save your setup some day... Other package managers often provide similar switches. Handy, especially for those who carelessly accept everything apt-get is proposing to do. Commented Nov 4, 2014 at 21:52

2 Answers 2

3

rm -i and mv -i forces these commands to ask for user confirmation before performing destructive actions (i.e. mv will only ask for confirmation if overwriting other files, while rm will always ask).

In fact I have this in my .bashrc:

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

Update: It is important to notice that with those aliases in place, you can use -f to revert back to system default of not asking for confirmation (a -f after a -i overrides it).

3
  • 1
    Man, that could be so tedious if you're deleting a directory with hundreds or thousands of files..
    – MrDuk
    Commented Nov 4, 2014 at 20:39
  • Nice one, is there that type of flag for more commands? Commented Nov 4, 2014 at 20:39
  • 2
    Not actually @MrDuk, with those aliases in place, if you specify the -f, it will ovirride the -i as these commands consider the rightmost parameter in this case, so this is actually just setting the default behavior as "ask first" but still allows you to force (i.e., revert back to the system default of not asking) in case you wish.
    – Marcelo
    Commented Nov 4, 2014 at 20:42
2

mv and rm both have a -i option that will prompt before destructive actions... but then again for rm every successful action is a destructive action so such an option is mostly useless in my opinion. In the case of mv, for interactive use I use -i by default and I find it to be an excellent precaution.

-n as in the git example you have is quite common: for example, make supports it. But it's not universal either. Nothing is.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .