Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

type is a Bash builtin that tells you how the current Bash shell interprets a name: as an alias, keyword, function, builtin, or executable found through PATH. Run type name for a quick explanation, or type -a name to see all matching definitions and executable locations. For portable scripts, use command -v to check whether a command is available.

What the Bash type command does

type is built into Bash; it is not normally a separate Linux program. It examines the current shell’s definitions and command lookup state without running the named command. This makes it useful when multiple things share a name—for example, an alias or function may take precedence over an executable.

Bash command lookup includes shell constructs as well as files found through PATH. The details depend on the current shell state and environment. See the Bash manual’s command search and execution rules.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Basic syntax and common results

The syntax is type [-afptP] name [name ...]. You can check several names in one command:

type cd pwd ls printf

For example, the following commands ask Bash about a builtin, a keyword, an ordinary command name, and a name that may not exist:

type cd
type if
type echo
type ls
type does-not-exist

Typical categories include:

What Bash recognizes Example name Typical description
Alias ll ll is aliased to ...
Keyword if, for, case if is a shell keyword
Function A user-defined function such as mycmd mycmd is a function
Builtin cd, export, echo cd is a shell builtin
Executable file ls, grep A pathname such as /usr/bin/ls
Unrecognized name does-not-exist A not-found diagnostic

These descriptions and paths are examples, not fixed output. Aliases and functions depend on shell configuration, while executable locations vary by system; for example, a system may merge /bin and /usr/bin.

Options for narrowing the result

Option What it does Example
-a Shows all relevant definitions or executable locations Bash finds for the name. type -a echo
-t Prints a category such as alias, keyword, function, builtin, or file. type -t cd
-p Prints an executable pathname found through Bash’s lookup behavior, if one is available. type -p bash
-P Forces a search of PATH for an executable, bypassing the normal preference for functions, aliases, and builtins. type -P echo
-f Suppresses function lookup; this is mainly a diagnostic option. type -f name

Show every match with -a

Names such as echo, true, and test may exist both as Bash builtins and as external executables. A name may also have more than one executable in PATH. Use:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
type -a echo
type -a true
type -a ls

Bash may report a builtin and a separate executable, or several executable paths. The exact matches and their order depend on the shell and system.

Print a category with -t

type -t returns a short category that is handy for Bash-specific diagnostics:

type -t cd
# builtin
type -t if
# keyword
type -t ls
# file

For a name Bash cannot resolve, do not depend on a particular text result. Use the command’s exit status when checking success.

Distinguish -p from -P

type -p name reports an executable pathname when one is found under Bash’s lookup behavior. A builtin such as cd has no executable pathname, so type -p cd prints no path. By contrast, type -P name specifically forces a search for an executable in PATH. A path from either option does not necessarily mean ordinary invocation selects that file: a function or builtin may take precedence.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose between type, command -v, and which

Need Use
Understand how the current Bash shell interprets a name type name
List aliases, functions, builtins, and executable matches type -a name
Get a short Bash category type -t name
Check command availability in a portable shell script command -v name
Find an executable pathname through Bash’s lookup type -p name or type -P name, depending on the question

type is Bash-oriented and its human-readable output is intended for diagnosis, not as a stable format for scripts. POSIX specifies the command utility, including -v and -V; it does not standardize Bash’s type builtin. For scripts intended to run across POSIX-like shells, use command -v. See the POSIX specification for command.

which is generally an external utility. It can help locate an executable, but it may not account for the current shell’s aliases, functions, keywords, or builtins. Prefer type for Bash-aware diagnosis and command -v for a portable availability check. The older Linux Shell Scripting Tutorial likewise cautions that which may not tell you what the shell will use.

Troubleshoot unexpected command selection

An alias changes an interactive command

If type ls reports an alias, Bash has a shell definition for that name. For example:

alias ls='ls --color=auto'
type ls

Remove that alias for the current shell with unalias ls. To bypass alias expansion for one command invocation, use command ls.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A function shadows an executable

A function can change a command’s behavior without changing any file in PATH:

ls() {
    echo "custom function"
}
type ls
declare -f ls

Use unset -f ls to remove that function from the current shell.

A builtin and an external executable share a name

Use type -a to see both kinds of match, such as for echo, printf, or test. Invoke a Bash builtin explicitly with builtin echo "hello". Use command echo "hello" to bypass a function or alias and perform normal command lookup, or use a full executable path when you need that particular file. The path is system-dependent.

Several executables are on PATH

Use type -a name to see matching executable paths. To inspect the search path one component per line:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
printf '%sn' "$PATH" | tr ':' 'n'

The first suitable executable in the effective search order normally wins, subject to shell constructs and command hashing. An empty component in PATH, as in /usr/local/bin::/usr/bin, can represent the current directory in some shell environments. That can cause surprising resolution and expose scripts to running an unintended file.

Bash remembers an old executable location

Bash can cache command locations. If an executable has been moved, replaced, or removed, clear the remembered locations with hash -r, then check again with type -a name.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use command checks safely in scripts

For a Bash script, check availability using the exit status rather than matching descriptive text:

if ! command -v curl >/dev/null 2>&1; then
    printf 'Error: curl is required but was not found in PATHn' >&2
    exit 127
fi

This pattern is also suitable for portable shell scripts. If the script specifically needs a Bash category, type -t can be used, but it is Bash-specific:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
if [[ $(type -t curl 2>/dev/null) == file ]]; then
    echo "curl resolves to an executable"
fi

Do not parse normal type output with a text search; wording and paths can vary. Also, finding a name does not prove every invocation will run an executable file. If a script requires a specific executable, resolve and validate its path:

tool=$(type -P mytool) || {
    echo "mytool executable not found" >&2
    exit 1
}

[ -x "$tool" ] || {
    echo "Resolved path is not executable: $tool" >&2
    exit 1
}

Why results differ between a terminal and a script

type reports the state of the shell process in which it runs, not a system-wide answer. An interactive terminal may have aliases or functions loaded from startup files that a noninteractive script does not have. Startup-file behavior varies according to whether Bash is interactive or a login shell, how it was invoked, and its options; a script should not assume .bashrc was loaded. Running under sudo, env, another shell, or a container can also change definitions and PATH.

For basic context when diagnosing a script, inspect:

printf 'shell: %sn' "$0"
printf 'Bash version: %sn' "$BASH_VERSION"
type -a command_name

To check whether the current shell is Bash, use [ -n "$BASH_VERSION" ]. The login shell listed for a user is not necessarily the shell currently interpreting a script.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Bash and other shells

This guidance is for Bash. Other shells, including zsh and ksh, may provide a type command, but options, behavior, and output can differ. In a POSIX-oriented script, use command -v rather than relying on Bash options such as -t.

For Bash’s built-in help, run help type; for the full manual, see man bash. The GNU manual’s Bash Builtins reference documents the syntax and options, and Linux man-pages’ type reference provides another command reference. The historical tutorial PDF describes Bash versions 3.x and 4.x; treat it as an archived introduction rather than a current compatibility guide.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.