Penguin

Can you think of a REALLY long command that you use on a regular basis? If so, aliases are for you!

An alias is a small command or name to execute a long string. They couldn't be easier to make. At your terminal, type:

alias <name>='<command to perform>'

If you type alias staz='echo you rock Staz', and then type staz at the terminal, you will be told that Staz rocks.

Of course there are much more useful aliases to be made than the one above!

Take for example: alias apt='sudo vim /etc/apt/sources.list'

Think about how many times you have edited this file. Wouldn't typing 'apt' be so much nicer? This alias will only last while you have this terminal window open if you want a permanent one, read on :)

To list the aliases available to you, simply type 'alias'.

To remove an alias do:

  • unalias <nameofalias>

Making aliases permanent

First we edit your ~/.bashrc file.

  • sudo vim ~/.bashrc

Now scroll down to find:

#if [ -f ~/.bash_aliases ]; then
#    . ~/.bash_aliases
#fi

Uncomment these three lines (or if they don't exist add them). Now save.

Now do:

  • vim ~/.bash_aliases

Add all your aliases (in the same format as above) with each being on a separate line. Save when you are done. Good stuff, now open a new terminal. Hopefully your aliases will work like a charm.

--- CategoryBeginners