linuxmacosterminalalias

mac how to save alias in computer


I created an alias on terminal, such as

alias hw="cd Desktop/2015hw"

but after I closed the terminal and do hw, there is an error message said there is no hw command.

I was wondering if we can save the alias on the computer. Also, if we have stored the alias on the computer, how would we check it? By check it, I mean like list all alias we have stored. Thanks.


Solution

  • Add the command to your .bashrc file

    echo "alias hw='cd Desktop/2015hw'" >> ~/.bashrc
    

    Keep in mind that your alias will only work when you are in your home (as you are using a relative path)

    echo "alias hw='cd ~/Desktop/2015hw'" >> ~/.bashrc
    

    Execute the saved alias by sourcing the file

    source ~/.bashrc