Create Aliases in Ubuntu

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.

15 thoughts on “Create Aliases in Ubuntu

  1. Zac

    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”

  2. grimfiend

    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?

  3. matlix

    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.

  4. Pingback: How can I run Oracle SQL Developer on JDK 1.6 and everything else on 1.7? « Ukrainian Oracle User Group

  5. fr3nch174l14n

    @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

  6. Spree

    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)

  7. Will

    Zac :
    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”

    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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>