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.
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
When making an alias with alias
, the alias is only valid until you close the terminal window. If you open another terminal window, the alias will no longer be present.
You can make an alias be valid for all terminal windows by placing it in your ~/.bash_profile or ~/.bashrc files (bash is the name of the terminal which Mac OS X ships with by default.)
Since Mac OS X does not load .bashrc by default, I would actually do:
echo "alias hw='cd ~/Desktop/2015hw'" >> ~/.bash_profile
When you want to delete the alias, you can open your ~/.bash_profile or ~/.bashrc files and delete it manually.
To open them, do open -a TextEdit ~/.bash_profile
or open -a TextEdit ~/.bashrc
Finally, to list all your current aliases, simply type alias
in Terminal.
your can start with type
ls -la
and then if you use bash typing
nano .bash_profile
or if you use zsh typing
nano .zshrc
then make alias save with ctrl + o
for activating
use
source ~/.bash_profile
or
source ~/.zsh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With