8

If you create an alias for example:

alias cls="clear"

It exists untill you kill terminall session. When you start a new terminal window the alias doesn't exist any more. How to create "permanent" alias, one that exists in every terminal session?

PPPPPPPPP
  • 660
  • 7
  • 14

1 Answers1

8

You can put such aliases in the ~/.bash_aliases file.

That file is loaded by ~/.bashrc. On Ubuntu 10.04, the following lines need to be uncommented to enable the use of ~/.bash_aliases. On Ubuntu 11.04 and later, it's already enabled:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

also

You can add the function below to your .bashrc file.

function permalias ()

{ 
  alias "$*";
  echo alias "$*" >> ~/.bash_aliases
}

Then open a new terminal or run source ~/.bashrc in your current terminal. You can now create permanent aliases by using the permalias command, for example permalias cls=clear.

AMH
  • 461
  • 5
  • 12
  • Perfect! exactly what I was looking for. I renamed it "mkalias". – PPPPPPPPP Oct 29 '13 at 00:53
  • If you have ruby installed on ubuntu, you can use aka (https://github.com/ytbryan/aka) to generate permanent aliases with a single command. eg. "aka g hello="echo helloworld" aka also auto-source the dotfile for you. There's also no need to open dot file with text editor. – ytbryan May 01 '15 at 17:01