I have command foo, how can I know if it's binary, a function or alias?


If you're on Bash (or another Bourne-like shell), you can use type.

type command

will tell you whether command is a shell built-in, alias (and if so, aliased to what), function (and if so it will list the function body) or stored in a file (and if so, the path to the file).

For more information on a "binary" file, you can do

file "$(type -P command)" 2>/dev/null

This will return nothing if command is an alias, function or shell built-in but returns more information if it's a script or a compiled binary.



The answer will depends on which shell you're using.

For zsh, shell builtin whence -w will tell you exactly what you want


$ whence -w whence
whence : builtin
$ whence -w man     
man : command 

In zsh you can check the aliases, functions, and commands arrays.

(( ${+aliases[foo]} )) && print 'foo is an alias'
(( ${+functions[foo]} )) && print 'foo is a function'
(( ${+commands[foo]} )) && print 'foo is an external command'

There's also builtins, for builtins commands.

(( ${+builtins[foo]} )) && print 'foo is a builtin command'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.