Published June 18th, 2007 by admin

Adding Terminal Aliases to Ubuntu


If you spend any time at all in the terminal you will soon discover that re-typing common commands gets old very quickly.

Linux has come up with a great solution to an age old problem.

The alias command.

This command allows you to create an alias or shortcut if you will to calling a longer command.

Let’s say you vnc another machine a lot. That machine happens to not have a DNS host name associated with it. You are always trying to remember the IP of that machine so you can VNC it.

The command to VNC our imaginary machine goes something like this:

vncviewer admin@192.168.245.231

That is a lot of typing for a common task.

Let’s simplify that. Type the following:

alias vncmybox=’
vncviewer admin@192.168.245.231′

Now you have created your first alias. Anytime during the session you type vncmybox it will run the command we assigned to that alias.

Here is the catch, as soon as you close the terminal all is lost.

Let’s make this change permanent.

Go to you home folder and create a file named:

.bash_aliases

(This can also be done via the terminal like so:

touch ~/.bash_aliases

Then add the alias we created earlier on the first line of this text file as so: (Remember to open this file from your home folder you will have to show hidden files by pressing ctrl + h when in your home directory)

alias vncmybox=’vncviewer admin@192.168.245.231′

Save the file and open the file named:

.bashrc

Find the section that is commented out (lines preceded with #’s) to looks like this:

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

Uncomment those lines. Save and close and then open a new terminal window.

Now type:

alias

It will list your aliases including the one we just added. Now you can go back and add other commonly used commands to your .bash_aliases file to ease your terminal tasks.

Technorati Tags: , , ,


3 Responses to “Adding Terminal Aliases to Ubuntu”

Feed for this Entry Trackback Address
  1. 1

    serenity Says

    I prefer ctrl+r myself.
    Set HISTSIZE=5000 in your bash config file, and press ctrl+r to search through your command history. Just hit enter when you’ve got the right command up – often with only 2-3 chars typed.

  2. 2

    Gabu Says

    Perfect! Thank You for this guide.
    It’s simple and easy to understand.

    I always forgot the command “echo 3 > /proc/sys/vm/drop_caches” to clear the cache. hee hee

  3. 3

    Will Says

    You have to remember to type ‘bash’ to restart the terminal for these changes to take effect.

Leave a Reply

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>