views:

146

answers:

4

How can I find out where an alias is defined on my system? I am referring to the kind of alias that is used within a Terminal session launched from Mac OS X (10.6.3).

For example, if I enter the alias command with no parameters at a Terminal command prompt, I get a list of aliases that I have set, for example, this is one of them

alias mysql='/usr/local/mysql/bin/mysql'

However, I have searched all over my system using Spotlight and mdfind in various startup files and so far can not find where this alias has been defined ( I did it a long time ago and didn't write down where I assigned the alias).

A: 

I found the answer ( I had been staring at the correct file but missed the obvious ).

The aliases in my case are defined in the file ~/.bash_profile

Somehow this eluded me.

Richard Fuhr
A: 

you can just simply type in alias on the command prompt to see what aliases you have. Otherwise, you can do a find on the most common places where aliases are defined, eg

grep -RHi "alias" /etc /root
ghostdog74
A: 

I think that maybe this is similar to what ghostdog74 meant however their command didn't work for me.

I would try something like this:

for i in `find . -type f`; do   # find all files in/under current dir
echo "========" 
echo $i                         # print file name
cat $i | grep "alias"           # find if it has alias and if it does print the line containing it
done

If you wanted to be really fancy you could even add an if [[ grep -c "alias" ]] then <print file name>

sixtyfootersdude
+1  A: 

Also in future these are the standard bash config files

  • /etc/profile
  • ~/.bash_profile or ~/.bash_login or ~/.profile
  • ~/.bash_logout
  • ~/.bashrc

More info: http://www.heimhardt.com/htdocs/bashrcs.html

sixtyfootersdude