Find Which Command Runs for a Name with type -a in Bash
Find which command runs with type -a name. It lists the alias, function, builtin and every file in PATH in order, which which misses, since it knows only files.
A command does something unexpected, and you suspect a function or an alias is shadowing the program you meant.
ls() { command ls "$@"; }
type -a ls
which ls
type -t ls
type -a echols is a function
ls ()
{
command ls "$@"
}
ls is /usr/bin/ls
ls is /bin/ls
/usr/bin/ls
function
echo is a shell builtin
echo is /usr/bin/echo
echo is /bin/echoThe type builtin reports how the shell would resolve each name, in the order it searches: alias, function, builtin, then files along PATH. With -a it prints all of them, so the output shows the function first and the real program second, and -t prints just the kind, such as function or builtin. which is a separate program that only searches PATH and therefore reports no trace of the function. See Bash builtins.
Aliases are only expanded in interactive shells, so inside a script type can show an alias that the script would not use unless shopt -s expand_aliases is set. command -v is the portable test for "does this exist" in POSIX sh, because type -a and -t are Bash options. A name hashed earlier may point to a stale path; hash -r clears the table.