How to enable confirmation alert when using 'rm' command to delete files / folders? [closed]
Asked Answered
M

3

37

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?

Melliemelliferous answered 13/5, 2015 at 7:55 Comment(2)
Have you tried rm -iSavoury
If you forget this on a command just do rm --help and you'll have all the answers right there.Reggiereggis
A
57

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.

Allyn answered 13/5, 2015 at 7:58 Comment(0)
L
21

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

Latini answered 13/5, 2015 at 7:56 Comment(3)
Sad to say I don't have the -I option on mac osEsbensen
@Juddling: I think you can use safe-rm instead.Melliemelliferous
Maybe you can use coreutils (brew install coreutils)!Adjutant
D
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

Didynamous answered 13/5, 2015 at 7:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.