How to cancel a rm command?

To accomplish request 1 you will need to use a more sophisticated program than yes to send y N number of times and then pass keyboard input through beyond that. You can't do it with rm except to always ask (rm -i) or to never ask (rm -f).

You can always abort rm by

  • pressing Control-C to interrupt it (sends SIGINT),
  • pressing Control-Z to stop it (sends SIGSTOP) and then killing it,
  • sending a SIGTERM (kill), or
  • sending it a SIGKILL (kill -9).

This won't undo any file operations rm has already performed, but they will prevent it from performing any further file operations. If the rm process is currently prompting for user input it is not actively unlinking any files so killing it will merely prevent it from continuing.


GNU rm supports -i, which I assume is what you are referring to and asks for confirmation for each file, but also -I, which is a little different:

-I     prompt once before removing  more  than  three  files,  or  when
       removing  recursively.  Less intrusive than -i, while still giv‐
       ing protection against most mistakes

As to whether it's possible to stop an interaction with rm after it has started, hitting Ctrl-C should do it.


with Ctrl+c you will be able to cancel the operation.

But if you look in your .bashrc file, you can comment the alias that force the confirmation, it use the -i param as expained dhag.

in you .bashrc you will find a entry like this :

alias rm='rm -i'

if you comment it, your rm -f will works directly

Tags:

Rm