opscape

Shell builtins · bash builtin

type

Show how the shell would interpret a name, as an alias, keyword, function, builtin or file on PATH.

type [-afptP] NAME...

9 of 9 examples run in Debian 13.7 on 2026-10-31 · manual: bash(1), SHELL BUILTIN COMMANDS

When you type a command name, bash checks, in order: aliases, shell keywords (if, [[), functions, builtins, and finally the directories in PATH. type answers which of those a name resolves to, and is the most accurate answer to "what actually runs when I type this?".

That makes it more useful than which, which only searches PATH and knows nothing about aliases, functions or builtins. type cd says it is a builtin; which cd finds nothing or points at a file that would never run. Use type -a to see every candidate in order of precedence, which explains why a newly installed program is "ignored" (an alias or an earlier PATH entry wins).

In scripts, type -t prints a single word (alias, keyword, function, builtin, file) that is easy to test, and type -P forces a PATH lookup. For a portable "is this command available?" check, command -v is the POSIX choice.

Examples

Find out what a name is

type ls cd if printf
explain
output
ls is /usr/bin/ls
cd is a shell builtin
if is a shell keyword
printf is a shell builtin

ls is a file in PATH, cd and printf are builtins, if is a keyword. The full path shown for ls is the one that would run.

Print a function's definition

greet() { echo "Hello, ${1:-world}"; }
type greet
output
greet is a function
greet () 
{ 
    echo "Hello, ${1:-world}"
}

For a function, type prints the body as bash stores it, reformatted. A quick way to inspect a function that some sourced file defined.

Reveal an alias

alias ll='ls -l'
type ll
shopt -s expand_aliases
type ll
output
/bin/bash: line 2: type: ll: not found
ll is aliased to `ls -l'

type reports what would really happen. In a non-interactive shell aliases are not expanded, so at first ll is "not found". Once expand_aliases is on, as it is in an interactive terminal, type shows the alias and its value.

List every match with -a

type -a echo printf test
explain
output
echo is a shell builtin
echo is /usr/bin/echo
echo is /bin/echo
printf is a shell builtin
printf is /usr/bin/printf
printf is /bin/printf
test is a shell builtin
test is /usr/bin/test
test is /bin/test

-a shows all the places a name is found, in precedence order. echo, printf and test are builtins, but coreutils also installs them as files; the builtin is what runs. Debian lists both /usr/bin and /bin because /bin is a symlink to /usr/bin.

Get a one-word answer with -t

greet() { :; }
for n in greet cd if grep nosuch; do
  printf '%-7s %s\n' "$n" "$(type -t "$n")"
done
output
greet   function
cd      builtin
if      keyword
grep    file
nosuch  

-t prints function, builtin, keyword, file or alias, and nothing for an unknown name. Convenient in a case statement.

Print only the path with -p or -P

type -p grep
type -p cd; echo "-p on a builtin printed nothing"
type -P printf
output
/usr/bin/grep
-p on a builtin printed nothing
/usr/bin/printf

-p prints the file that would run, or nothing if the name is not a file. -P searches PATH even when a builtin or function would take precedence.

An unknown name returns 1

type kubectl
explain
outputexit 1
/bin/bash: line 1: type: kubectl: not found

When none of the names are found, type prints an error and returns 1. With several names, the status is 1 if any of them is missing.

See that bash remembered a path

grep -c TODO notes.txt
type grep
output
1
grep is hashed (/usr/bin/grep)

After a command runs, bash caches its location, and type reports it as hashed. If you move a program, hash -r clears this cache.

Detect a function shadowing a command

ls() { echo "this is not the real ls"; }
type -t ls
ls
command ls scripts
output
function
this is not the real ls
backup.sh
greet.sh

A function named like a command wins over the file in PATH. type exposes it, and command skips functions to reach the real program.

Common pitfalls

  • Using which to debug "why does this command behave oddly". It ignores aliases and functions; type -a shows what actually runs.

  • Testing type foo without silencing it in a script: it prints a line on success and an error on failure. Use type foo >/dev/null 2>&1 or command -v foo >/dev/null.

  • type -p prints nothing for builtins, which can look like "not installed". Use -P when you specifically need the file.

GNU vs BSD and macOS

The examples above ran the GNU/Linux version. These are the differences that matter on macOS and the BSDs (written from their documentation, not run here).

  • type is required by POSIX, but its options are not; dash's type has none of -a, -t, -p or -P. zsh supports -a and uses whence for the rest. Use command -v for portable checks.

Options worth knowing

A selection, described in our own words. For the full list, see bash(1), SHELL BUILTIN COMMANDS.

OptionWhat it does
-aShow every alias, keyword, function, builtin and file matching the name.
-tPrint a single word: alias, keyword, function, builtin or file.
-pPrint the path of the file that would run, or nothing if it is not a file.
-PSearch PATH for the name even when it is also a builtin or function.
-fSkip shell functions when looking up the name.

Related