How to enable confirmation alert when using 'rm' command to delete files / folders?

webster picture webster · May 13, 2015 · Viewed 26k times · Source

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?

Answer

Mureinik picture Mureinik · May 13, 2015

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.