Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know I can create an alias for untar like this

alias untar=’tar -xvzf’

How do I make this persist from session to session, because it seems it is lost when I reconnect?

share|improve this question
up vote 2 down vote accepted

As already stated, ~/.bashrc is where you want to place them. You may like this little function I use to create aliases (place it in your ~/.bashrc file).

function mkalias ()
        if [[ $1 && $2 ]]
        echo -e "alias $1=\"$2\"" >> ~/.bashrc
        alias $1="$2"

The basic syntax is: mkalias <name> "<command>"

an example would be: mkalias trsh "mv --target-directory=$HOME/.Trash"

the command is always placed in quotes in case there are spaces.

share|improve this answer
Thanks a lot for the code snippet. I'm new to bash will try to get this work :) – asksuperuser Feb 28 '10 at 20:26
This function has a small bug. You forgot to quote $2 in alias $1=$2. See:… – Tyler McHenry Mar 1 '10 at 0:05
+1, and fixed small stuff. – nik Mar 1 '10 at 0:15

You usually write the alias in $HOME/.bashrc (if you are using the bash shell).

Otherwise take a look at this wikipedia article to know which configuration file your shell will read.

In order to know which shell you are using look at the SHELL environment variable with:

$ echo $SHELL 
share|improve this answer
Thanks, I see I use bin/bash – asksuperuser Feb 28 '10 at 20:26

You can add it to your .profile or .bashrc. There are usually some other aliases there, so follow those examples and you should be just fine.

share|improve this answer

You must log in to answer this question.