When I use the command rm -rf, I want to make sure a prompt always appears before deleting a file, so I tried adding this to ~/.bashrc
alias 'rm -rf'='rm -rfi' But it doesn't work. How can I fix this?
When I use the command rm -rf, I want to make sure a prompt always appears before deleting a file, so I tried adding this to ~/.bashrc
alias 'rm -rf'='rm -rfi' But it doesn't work. How can I fix this?
Confirmation is a weak way to achieve the result you want: not deleting files you didn't want to delete. I can ask you to confirm 10 times in a row, but if since you just asked me to delete mispeled.txt you will not realize your error until after you confirmed it.
Better to use trash or similar command on your system that sends files to the (recoverable) "recycle-bin". There is an RPM build of the trash-cli package at rpmfind.net but I can't vouch for that version. When in doubt build it yourself from the source code.
As noted in the comments it is a bad idea to alias rm at all, because it will come back to bite you when you are in a shell that has no protective alias and your brain is accustomed to having a "safe" rm.
trash-cli that provides a /bin/trash. In your ~/.bashrc, you can just do this instead:
alias rm='rm -i' This way, when you type rm -rf example-dir, Bash translates it to rm -i -rf example-dir.
Note that for interactive login shells, ~/.bash_profile is used instead. To make login shells also use ~/.bashrc, simply add this to your ~/.bash_profile:
[ -f ~/.bashrc ] && . ~/.bashrc Now ~/.bashrc will always execute any time you open a terminal or ssh session.
f --> force, never prompt
i --> prompt every time
If you need to be prompted, just use rm -i in the alias. You could have 2 aliases (rmf and rmi) if you wish to have both.
-i takes precedence over -f, so rm -rf -i will still ask for confirmation. rm -f -i will prompt, but rm -i -f will not prompt. rm on OS X El Capitan 10.11.6: "The -f option overrides any previous -i options." Seeing as there are different implementations of this program, I'd advise against aliasing rm at all. rm -rfi would give you the prompt, however rm -i -rf would not. Your alias make your commands to the latter one.
In addition to valid answers, I would advise you to separate your aliases into ~/.bash_aliases, and source it simpy in the end of ~/.bashrc
if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi As has been already said, your alias is twisted into mutually exclusive options:
‘-f’ ‘--force’ Ignore nonexistent files and missing operands, and never prompt the user. Ignore any previous ‘--interactive’ (‘-i’) option.
^ taken from info rm.
Thus, the following would work:
alias rm='\rm -i'