Alias not working in Debian

Posted on

Problem :

I’ve the following alias in ~/.bashrc

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

But it still doesn’t prompt me. Am I missing something?

Solution :

These files – .bashrc and .bash_profile – aren’t reloaded automatically after you save changes to them. bash doesn’t monitor them for changes, they are only automatically evaluated during bash invocation.

After changing something, you need to explicitly load them. There are basically two ways:

  • source filename or the equivalent . filename will evaluate filename‘s contents in the current session. This is the easiest, if all you did was add or change existing definitions.
  • Start a new bash session, optionally closing your current one. Depending on how your terminal emulator works, you might need to launch bash -i (for .bashrc) or bash --login (for .bash_profile) explicitly.

In modern, tabbed terminal emulators, this allows you to keep e.g. vi .bashrc open in one tab, edit and save repeatedly, while opening new tabs to test the results. In case you mess it up and the new tabs are not useable, you can also easily revert any changes.

For more information on these files and when bash evaluates them, see man bash‘s section INVOCATION.

Leave a Reply

Your email address will not be published. Required fields are marked *