35

I have found that we cannot recover files/folders when deleted using rm command from here

But, is it possible to add a confirmation alert when using rm command in the terminal?

Community
  • 1
  • 1
webster
  • 3,902
  • 6
  • 37
  • 59

3 Answers3

52

You can use the -i flag:

rm -i someFile.txt

If you're concerned you may forget to do this, you could alias the rm command:

alias rm="rm -i"

If you place this alias in one of the files sourced when you start a session (e.g., .bashrc), you'll have it available in all your future terminal sessions.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
20

You want to use rm -i or rm -I

According to the man pages: man rm

-i prompt before every removal

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

Community
  • 1
  • 1
Leon
  • 12,013
  • 5
  • 36
  • 59
3

As above or perhaps

alias rm="rm -i"

But be careful doing this if you use multiple accounts and one does not have this alias

Ed Heal
  • 59,252
  • 17
  • 87
  • 127