Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine where a UNIX alias is defined

Is there a (somewhat) reliable way to get the 'origin' of a command, even if the command is an alias? For example, if I put this in my .bash_profile

alias lsa="ls -A"

and I wanted to know from the command-line where lsa is defined, is that possible? I know about the which command, but that doesn't seem to do it.

like image 240
user1516425 Avatar asked Jul 26 '12 01:07

user1516425


1 Answers

As Carl pointed out in his comment, type is the correct way to find out how a name is defined.

mini:~ michael$ alias foo='echo bar'
mini:~ michael$ biz() { echo bar; }
mini:~ michael$ type foo
foo is aliased to `echo bar'
mini:~ michael$ type biz
biz is a function
biz () 
{ 
    echo bar
}
mini:~ michael$ type [[
[[ is a shell keyword
mini:~ michael$ type printf
printf is a shell builtin
mini:~ michael$ type $(type -P printf)
/usr/bin/printf is /usr/bin/printf
like image 54
kojiro Avatar answered Oct 01 '22 07:10

kojiro