Thursday, 4 April 2019

shell - How to store a Unix alias?


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?



Answer



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 ""


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


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


No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...