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.

Tagged with:
 

10 Responses to Create Aliases in Ubuntu

  1. ander says:

    I tried this with Linux Mint 9, but it had no effect.

  2. Hailon says:

    @ander
    Try .bashrc

  3. hippie says:

    @ander you did it wrong then. instead of pico, use nano. Pico is not installed by default.

  4. Zac says:

    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”

  5. grimfiend says:

    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?

  6. grimfiend says:

    Disregard, just found my answer….thx

  7. matlix says:

    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.

  8. brockangelo says:

    sweet – thanks!

  9. Igor says:

    thanks much!

  10. [...] You’ll probably want to do something to make this easier on yourself such as setting up an alias in Linux or maybe another environment variable in [...]

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> <pre lang="" line="" escaped="" highlight="">