I\'m on OSX and I need to put something like this, alias blah=\"/usr/bin/blah\"
in a config file but I don\'t know where the config file is.
On OS X you want to use ~/.bash_profile. This is because by default Terminal.app opens a login shell for each new window.
See more about the different configuration files and when they are used here: What's the difference between .bashrc, .bash_profile, and .environment?
and in relation to OSX here: About .bash_profile, .bashrc, and where should alias be written in?
In my .bashrc
file the following lines were there by default:
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
Hence, in my platform .bash_aliases
is the file used for aliases by default (and the one I use). I'm not an OS X user, but I guess that if you open your .bashrc
file, you'll be able to identify what's the file commonly used for aliases in your platform.
I just open zshrc with sublime, and edit it.
subl .zshrc
And add this on sublime:
alias blah="/usr/bin/blah"
Run this in terminal:
source ~/.bashrc
Done.
Apple switched their default shell to zsh, so the config files include ~/.zshenv
and ~/.zshrc
. This is just like ~/.bashrc
, but for zsh. Just edit the file and add what you need; it should be sourced every time you open a new terminal window:
nano ~/.zshenv
alias py=python
Then do ctrl+x, y, then enter to save.
This file seems to be executed no matter what (login, non-login, or script), so seems better than the ~/.zshrc
file.
The default shell is bash, and you can edit the file ~/.bash_profile
and add aliases:
nano ~/.bash_profile
alias py=python
Then ctrl+x, y, and enter to save. See this post for more on these configs. It's a little better to set it up with your alias in ~/.bashrc
, then source ~/.bashrc
from ~/.bash_profile
. In ~/.bash_profile
it would then look like:
source ~/.bashrc
Create alias at bottom of the file
alias alias_name='command to do'
eg: alias cdDesktop='cd /Desktop'
Save the file
source .bashrc
source ~/.bashrc
Open terminal (Ctrl+Alt+T) & type cdDesktop & press enter
I need to run the Postgres database and created an alias for the purpose. The work through is provided below:
$ nano ~/.bash_profile
# in the bash_profile, insert the following texts:
alias pgst="pg_ctl -D /usr/local/var/postgres start"
alias pgsp="pg_ctl -D /usr/local/var/postgres stop"
$ source ~/.bash_profile
### This will start the Postgres server
$ pgst
### This will stop the Postgres server
$ pgsp