I really like bash aliases, it annoys me that every time I want to add a new alias I have type two commands:

echo "alias \"short-cmd\"='long-command'" >> ~/.bash_aliases
source ~/.bash_aliases

Any way I can create an alias permanently with a single command?

  • 1
    You can use . instead of source and press [Alt]+[.] to insert the last argument of the previous command, so you can do the equivalent of source ~/.bash_aliases.sh in just four keystrokes without the need for any custom functions.
    – n.st
    May 8, 2014 at 16:34
  • The point is do everything in a single command
    – RSFalcon7
    May 8, 2014 at 17:14

3 Answers 3


Here is my workaround, the function palias (aka permanent alias):

function palias ()  {

    if [ $# -ne "2" ] ; then
        error "Usage: palias short-alias \'long-alias\'"

    alias $1="$2"
    alias $1 >> ~/.bash_aliases
  • 1
    FYI: Running alias without a definition will show the current definition. You can use this to make sure the quoting works right—e.g., your current method fails if the definition contains single-quote. alias "$1" >> ~/.bash_aliases does not. I suggest switching (in both your answer and on your systems). Also, you shouldn't be using echo -e there; you want plain echo (if you don't want to switch to alias for some reason).
    – derobert
    Mar 28, 2014 at 17:59
  • @derobert I solved some expansion problems and applied the alias trick you told me. Thanks a lot
    – RSFalcon7
    May 8, 2014 at 17:38

My "two keystroke solution" (one letter and the return key) is to have this alias set up:

alias a='. ~/.bash_aliases'

Then whenever I update my .bash_aliases file I just type areturn

One step further is maintain them across machines, using github:

bup () { [ $# = 1 ] && { cp -v ~/$1 ~/Dropnot/setups; cd ~/Dropnot/setups; git fetch; git merge origin/master; git add $1; git commit -m"$1 update"; git push origin master; cp -v $1 ~; cd -; } || echo "Error - no filename passed!";}

Usage: bup [file] # file must be in ~, is usually a dot file]


There are several files that run when you login to your shell including ~/.bash_profile and possibly ~/.bashrc and ~/.bash_aliases if those are referenced in your ~/.bash_profile file. To have an alias available every time you login, just put the command that creates the alias in one of those files.


  • I know that! The point is to make it permanent without resourcing any file
    – RSFalcon7
    Mar 28, 2014 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.