Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Recently i was adding some command aliases to .bash_aliases file in user home folder. I am wondering if there is some script that i can run to add aliases to that file. What I mean is : some script that first I can add as command alias and after that for example if I run command lets say


it will execute the script.

The script will do the following job: Go to the end of the text file. Add line for example :alias aosunpack='/home/elementalfx/aosfirmware/unpack-aos-kernel-g10'

Then save the file. And finally reload the bash_aliases with command . ~/.bash_aliases

But to make it even better script will first ask for alias name and then for a command to execute or file to execute.

Thats the thing that I dont know how to do. Can somebody lead me to the right direction?

share|improve this question
up vote 2 down vote accepted

Adding aliases is manual labour but can be done with a 1-liner on command line. This will create your alias and add it to bash_aliases and also reload them:

echo "alias aosunpack='/home/elementalfx/aosfirmware/unpack-aos-kernel-g10'" >>
~/.bash_aliases && source ~/.bash_aliases

All you need to do is adjust it to your commands for any other command you want (if you put those into a text file you can omit the && source ~/.bash_aliases and add source ~/.bash_aliases at the end. This will not prevent duplicates but the last one added will be the active one.

Partly taken from a comment by hobs from this question: How to create a permanent "alias"? There are more good answers and comments in that topic.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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