Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Viewing and Searching Files

Bash type command

Reference for the Bash type builtin: find out whether a name is an alias, keyword, function, builtin or file, list every match with -a, and use -t in scripts.

type is a Bash builtin that tells you what the shell will do with a word if you use it as a command. A word can be an alias, a keyword (such as if), a function, a builtin (such as cd) or an executable file found on PATH. The shell checks them in that order, and type reports the first one it finds, or all of them with -a.

It is the right tool for "why does this command behave differently than I expect?" questions.

Terminal
type [-afptP] NAME...

Try it

Bash What kind of thing is it?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Several matches and how to bypass them

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
type [-afptP] NAME [NAME ...]
Option Description
-a Show all places that contain an executable or definition with this name.
-f Ignore shell functions, as if command was used.
-t Print one word: alias, keyword, function, builtin or file; nothing if not found.
-p Print the file path only if the name resolves to a file (nothing for builtins).
-P Force a search of PATH, even if an alias or builtin exists.

Returns: 0 if all names were found, 1 if any was not. For a missing name, type prints a "not found" message to standard error (except with -t).

Usage notes

  • Lookup order: alias, keyword, function, builtin, then PATH. Knowing it explains why a function called ls hides /bin/ls.
  • Bypass a wrapper: command ls, \ls (skips aliases), builtin cd, or the full path /bin/ls.
  • Functions are printed with their body, which makes type myfunc a quick way to read a function loaded from a startup file.
  • Hashed commands are shown as ls is hashed (/bin/ls). The hash table remembers where the shell found a command last time; hash -r clears it.
  • Portable alternative: command -v name prints a path (or the word for builtins) and works in any POSIX shell. type exists in POSIX too, but its output format is not specified, so parse nothing from it; only use the exit status.
  • Use -t in scripts when you need to branch on the kind: [[ $(type -t foo) == function ]].
  • Not a Bash-only idea. type exists in dash and zsh with different messages; whence and which are shell- or system-specific relatives.
  • Because it is a builtin, there is no /usr/bin/type to run from another program, and find -exec type will not work.