Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out where alias (in the bash sense) is defined when running Terminal in Mac OS X

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:

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).

like image 443
Richard Fuhr Avatar asked Apr 10 '10 18:04

Richard Fuhr


People also ask

Where are bash aliases defined?

A Bash alias is a method of supplementing or overriding Bash commands with new ones. Bash aliases make it easy for users to customize their experience in a POSIX terminal. They are often defined in $HOME/. bashrc or $HOME/bash_aliases (which must be loaded by $HOME/.

How do I find my aliases on Mac?

How to Quickly Access & Show Original from an Alias in Mac OS. You also can select an alias and then hit Command + R to quickly jump the original item in the Finder as well, or you can right-click and choose “Show Original” from the contextual menu, use whichever method is fastest for you.

Where are bash alias stored?

Aliases allow you to define new commands by substituting a string for the first token of a simple command. They are typically placed in the ~/. bashrc (bash) or ~/. tcshrc (tcsh) startup files so that they are available to interactive subshells.

Which command can you run to view your currently defined aliases?

You can see a list of defined aliases on your profile by simply executing alias command.


2 Answers

For OSX, this 2-step sequence worked well for me, in locating an alias I'd created long ago and couldn't locate in expected place (~/.zshrc).

cweekly:~ $ which la la: aliased to ls -lAh  cweekly:~$ grep -r ' ls -lAh' ~ /Users/cweekly//.oh-my-zsh/lib/aliases.zsh:alias la='ls -lAh' 

Aha! "Hiding" in ~/.oh-my-zsh/lib/aliases.zsh. I had poked around a bit in .oh-my-zsh but had overlooked lib/aliases.zsh.

like image 96
cweekly Avatar answered Oct 21 '22 18:10

cweekly


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 
like image 38
ghostdog74 Avatar answered Oct 21 '22 17:10

ghostdog74