Jan 052009
 

Sponsored Link

Aliases are shortcuts for certain commands. For example, if your current directory is /usr/bin and you want to navigate quickly to /var/cache/apt/archives you can do a "cd /var/cache/apt/archives", but this is quite long and you probably want to save time. So this is where aliases come in help. You can do only a "archive" or a "pak" command and the same action is accomplished.

First, edit your ~/.bashrc

#vi ~/.bashrc

and make sure that it contains the following three lines (if not add them editing the file)

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

After this all you have to do is edit your ~/.bash_aliases file and add your own aliases.

#vi ~/.bash_aliases

Examples

alias dld='cd ~/downloads'

alias x11='nano /etc/X11/XF86Config-4′

alias pak='cd /var/cache/apt/archives'

Save and exit the file.

In the above examples, "dld", "x11″ and "pak" commands will execute the exact command from the right side of the equal sign.

Sponsored Link

 Posted by at 12:17 am
  • Gordon

    Why bother with the extra file, just put the aliases directly in the ~/.bashrc file.

  • wolfric

    Excellent, now when I type urnar instead of unrar it still works!

    Thanks

  • lied

    @Wolfric:

    Have a look at the ZSH instead of Bash. It has a autocorrection feature… Happy mistyping :)

  • http://lightlinux.blogspot.com Mikko

    I suppose everyone who can edit files using VI can already set aliases in .bashrc :-)

  • http://wiki.classesarecode.net John Allen

    Totally insane to use aliases for cd, IMHO

    Why not use the CDPATH variable instead.

    eg.
    CDPATH=.:/var/cache/apt:~/

    now “cd archives” will look in current dir, then /var/cache/apt, and ~/

  • luser

    Automake fails when using bash and CDPATH is set. If you’re a developer or build your programs from source it can be annoying sitting there for a few minutes until you remember the build is failing because the CDPATH environment variable is set. I’m not sure if that bug has been fixed yet.

    IMO, the best and safest solution is to either use tab completion or learn how to type.

  • JustinD

    I use it for SSH sessions, and prefer this file instead of .bashrc to get a clear overview