I have MySQL installed (MAMP, Mac OS X) but need to call it by the full path each time I access it from the shell. I created an alias: alias mysql='/Applications/MAMP/Library/Bin/mysql
, but this only lasts as long as my terminal/Bash session.
What is an effective way for establishing permanent aliases that will work across users? (I need to be able to execute commands from PHP). Should I set up aliases in the Bash start up script (how is that done?), or is it better to edit the sudoers file? (Could use an example of that as well..)
Thanks--
EDIT- Based on answer:
I just tried creating a ~/.bashrc
and wrote the following:
alias mysql='/Applications/MAMP/Library/bin/mysql'
But this doesn't seem to have any effect. Is there a special syntax for this file?
Create an alias On your Mac, do one of the following: Select the item, then choose File > Make Alias. You can create as many aliases for an item as you want, then drag them to other folders or to the desktop.
Add the command to your ~/.bashrc
file.
To make it available to all users, add it to /etc/profile
.
.bash_profile
or .profile
.bashrc
.zshrc
Traditionally, to add a permanent alias, you need to open the dot file and write alias manually like:
alias hello="echo helloworld"
And remember to source the dot file to have it take effect. To source the dot file on ubuntu's bash, type source .bashrc
To make the alias available to all users, write to /etc/profile
instead of the dot file. Remember to type source /etc/profile
for the new alias to take effect.
If you simply want a temporary alias, you do not need to write to dot file. Simply type that same command (alias hello="echo helloworld
) on the terminal.
Note that a temporary alias created through the alias
command will disappear once the shell is closed.
If you are looking for a single command to generate aliases without open the text editor, read on.
If you have ruby installed on ubuntu, you can create permanent alias with a single command using aka.
gem install aka2
For example:
aka generate hello="echo helloworld" #will generate a alias hello="echo helloworld" aka destroy hello #will destroy the alias hello aka edit hello #will prompt you to edit the alias.
With aka, there is no need to write to the dot file with a text editor. And no need to source the dot file too.
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