Creating permanent executable aliases
- Different shell uses different dot file to store aliases.
- For mac, the bash shell uses
.bash_profile
or.profile
- For ubuntu, the bash shell uses
.bashrc
- If you are using zsh shell and ohmyzsh plugin, the dot file is
.zshrc
Traditionally, to add a permanent alias, you need to open the dot file and write alias manually like:
alias hello="echo helloworld"
And remember to source the dot file to have it take effect. To source the dot file on ubuntu's bash, type source .bashrc
To make the alias available to all users, write to /etc/profile
instead of the dot file. Remember to type source /etc/profile
for the new alias to take effect.
If you simply want a temporary alias, you do not need to write to dot file. Simply type that same command (alias hello="echo helloworld
) on the terminal.
Note that a temporary alias created through the alias
command will disappear once the shell is closed.
If you are looking for a single command to generate aliases without open the text editor, read on.
If you have ruby installed on ubuntu, you can create permanent alias with a single command using aka.
gem install aka2
For example:
aka generate hello="echo helloworld" #will generate a alias hello="echo helloworld" aka destroy hello #will destroy the alias helloaka edit hello #will prompt you to edit the alias.
With aka, there is no need to write to the dot file with a text editor. And no need to source the dot file too.