Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

3 Answers 3

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 ]]
        then
        echo -e "alias $1=\"$2\"" >> ~/.bashrc
        alias $1="$2"
        fi
}

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: superuser.com/questions/114690/… –  Tyler McHenry Mar 1 '10 at 0:05
    
+1, and fixed small stuff. –  nik Mar 1 '10 at 0:15
add comment

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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.