How to Create an Alias in Ubuntu
If you run the same commands in Linux (or Ubuntu) all the time, you can add what is called an “alias” to your user account. For example, I regularly type:
ls -alh
So I setup an alias so that I can just type la. (also, see my Top 10 Aliases list) To do this, simply edit your “profile”. Bash is the program that you typically use when you are in a command shell, so it may be called your “bash profile”. Your profile is in your Home folder and stores all of your preferences. Just edit the “.profile” or the “.bash_profile” if it exists.
cd ~
pico edit .profile
Add the following code to the bottom:
alias la='ls -alh'
Now when you are typing at the command prompt, you just type la and it acts like you typed ls -alh. Pretty handy.
I tried this with Linux Mint 9, but it had no effect.
@ander
Try .bashrc
@ander you did it wrong then. instead of pico, use nano. Pico is not installed by default.
Nice article–I could’t remember the syntax for this command, so this we helpful!
Just a quick tip: You can also type the “alias la=”ls -alh” directly into the terminal to create an alias. For example, entering the following command (minus the “user:~$” part) would allow me to enter “la” in place of “ls -alh”:
user:~$ alias la=”ls -alh”
I want to set up an alias that uses multiple commands. Can this be done? If so, how does one go about doing it using the alias command only?
Disregard, just found my answer….thx
Another way is to create the file ~/.bash_aliases and add your alias command there. .bashrc should check to see if the file exists with the lines
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
then just type source .bashrc. Slightly tidier.
sweet – thanks!
thanks much!
Pingback: How can I run Oracle SQL Developer on JDK 1.6 and everything else on 1.7? « Ukrainian Oracle User Group
@Zach if you type the alias command directly in terminal, this will be effective only during the time of your session. Reboot your machine and the alias will have disappeared. For this reason, it had to be hard-coded in .bashrc
Found it useful. I would like to contribute to this, we can also directly enter like this open the file in your favourite editor and enter the alias line and to make the change into effect have to run the following command from home directory
source .bash_profile/.profile
After this you can see the change made.(the alias will start working)
For aliasing multiple commands see here: http://ubuntuforums.org/showthread.php?t=1191607
True, just keep in mind though, that it would only work for your current terminal session, as when you exit out of the session, all aliases you typed in that way would be lost
In Ubuntu 12.04, aliases should be placed in ~/.bash_aliases