User Tools

Site Tools


bash_aliases

Creating and using Bash Aliases

by Drbongo - founder of Vinux

When in the terminal, either gnome-terminal or a console, all interaction with your computer requires typing. Sometimes the amount of typing required can be tiresome. To help with this you can create and use aliases.

Aliases are stored in your home directory in a file called ".bash_aliases". Aliases are in the format:

  1. It is possible that the aliases are not activated by default, in such case the file will be in bash_aliases_vinux instead.
  alias shortcommand='long command goes here'

Note:The apostrophes may be replaced with quotation marks ("). When you have added a new alias you can then type the short command and get the same output as if you had typed the longer command.

Aliases can also make commands behave differently from the way they would normally. If you would like to execute something in its normal way without its alias type a backslash "\" before the command.

Example

by Storm Dragon

When you type 'date' from the command line you will get something like this:

Tue Nov 30 18:32:55 EST 2010

I wanted to display the date in a more friendly format. Here are the steps for adding this bash alias to your system:

  1. Open a terminal with "Ctrl+Alt+t".
  2. type:
    nano ~/.bash_aliases

    Nano will open with a text file that may or may not be blank.

  3. Move to the end of the file by pressing the down arrow. Note:If there is text on the final line press right arrow until you get to the end of the line. Press "enter".
  4. On a blank line at the end of the file type:
    alias date="date +'%I:%M%p%n%A, %B %d, %Y"
  5. To save and exit the file press Control+O followed by Control+X.

With the alias in place, when you type

  date

you will now get something like:

06:33PM Tuesday, November 30, 2010

Note:Remember, if you would like the original format just type:

\date

One final thing, after you have added a new alias, before you can use it, you need to reload things so that bash will know about your new creation. To reload everything either exit the terminal and restart it or type:

source ~/.bashrc

The new alias will now work as expected.

Hint

If you want to avoid duplicating an existing command, capitalize the first letter of your alias.

Aliases in Vinux

Vinux comes with a bash aliases file. This is a list of aliases that can simplify the use of many common commands and their related options. It is informative just to view the list to understand what aliases can be used for.
These aliases are not enabled by default. If you would like to try them simply run the following code in a terminal:

  1. To open a terminal, press "Ctrl+Alt+t".
  2. At the terminal prompt, type:
      mv .bash_aliases_vinux .bash_aliases

    This moves the Vinux aliases to the file where bash aliases are stored.

  3. To see all your brand new aliases, type:
    alias

    Press "enter".

  4. You can also try typing:
    a

    the alias for alias.

  5. To list a specific alias type:
    alias alias-name

Peter Tesar and Rill contributed to this article.

bash_aliases.txt · Last modified: 2013/07/03 14:27 (external edit)