Results 1 to 1 of 1

Thread: How to: Create an alias for terminal commands

  1. #1
    Join Date
    Aug 2009
    Ubuntu 12.10 Quantal Quetzal

    How to: Create an alias for terminal commands

    I have seen many people asking how to create an alias for terminal commands.This is a small how to: to show you how to create an alias.Ofcourse creating an alias for frequently using commands will be very helpful.

    How to create an alias?

    We often use update and upgrade command in our system.So let me show you how to create an alias for those commands.

    alias custom_command='original_command'

    So for creating an alias for update and upgrade we should type the following in terminal,
    alias update='sudo apt-get update'
    alias upgrade='sudo apt-get upgrade'
    Now if you want to update,you can simply type update in terminal.And it will perform the action of sudo apt-get update for upgrading simply type upgrade.If you want to create an alias for both the commands then you should add an alias like this,
    alias updg='sudo apt-get update && sudo apt-get upgrade'
    Like this you can create an alias for any commands you wish.These custom commands will work until you close your terminal.So to add this permanently,you should add the commands to ~/.bashrc or ~/.bash_aliases.

    How to add these commands to ~/.bashrc or ~/.bash_aliases file?

    Edit the ~/.bashrc file,and add the commands at the end file,
    gedit ~/.bashrc

    After adding the commands you should run the following command in terminal to refresh your bashrc configuration.
    source ~/.bashrc
    Now you have added the alias permanently..Hope this helps someone..

    If you just want to add one or two aliases, use .bashrc. If you want to add more then i recommend you to use .bash_aliases.It will prevent you from messing up the files.It's always a good idea to add your custom commands in .bash_aliases.Good Luck..!
    Last edited by karthick87; December 27th, 2010 at 08:21 AM.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts