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
?
Now, when you delete a file using the “rm” command, a confirmation displays to make sure you want to delete the file. Press “y” to delete the file, or “n” to keep it. When you enter “rm –r” to delete a folder, you will also get the confirmation.
The good news is that, rm has an -i flag which prompts (to confirm) you before removing every file. As you can see, you're prompted to confirm the remove operation of the file hello. txt. To confirm, press y and then press <Enter>.
Syntax: rm command to remove a file When rm command used just with the file names, rm deletes all given files without confirmation by the user.
If you use the del /p command, you'll see the following message: FileName, Delete (Y/N)? To confirm the deletion, press Y.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With