Session and utilities

The type command

Shows what a command name is: alias, keyword, function, shell builtin or external program, and where it is. It is how you find out what the terminal will actually run.

Syntax

type [-a|-t|-p] nombre...Try it in the terminal →

Most useful options

-aShows all matches, including those hidden by another one, such as an alias and a program with the same name
-tPrints only the type word: alias, keyword, function, builtin or file
-pPrints the path of the program that would run. Prints nothing if the name is an alias, a function or a builtin

Copy-ready examples

$ type lsshows where the ls program that runs is located.

Example output

ls is /usr/bin/ls
$ type -t cdcd is a shell builtin, so there is no file on disk for it.

Example output

builtin
$ type -t llif you have the ll alias defined, it confirms it.

Example output

alias
$ type -p lsjust the path, ready to use in a script.

Example output

/usr/bin/ls

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
bash: type: nonexist: not foundThe name does not exist as an alias, function, builtin or program in PATH.Check the spelling or install the missing program.
No error messageThe program is in a folder that is not listed in PATH. type only searches the folders in PATH.Add the folder to PATH or type the full path of the program.
No error messageYou used -p with an alias. There is no file to show, so it prints nothing.Remove -p or use type without options to see the type.

Typical mistakes

  • type shows the first match according to the precedence order: alias, keyword, function, builtin, and then program.
  • If a name is an alias or a function, the program on disk does not run even if it exists. Use -a to see everything.
  • Results depend on the session PATH. A script run with another PATH may find a different program.

Differences from similar commands

  • which: searches only external programs in PATH. type also recognizes aliases, functions and builtins.
  • command -v: is the portable way to check a command in POSIX scripts. type is specific to Bash.
  • whereis: searches binaries, manuals and sources in fixed paths, not in PATH.

FAQ

What is the difference between type and which?

which only checks external programs in PATH. type also recognizes aliases, functions and shell builtins.

How do I see every program with the same name?

With type -a name. It shows every match in the order the shell would search for it.

What is type -t for?

To know the type of a name inside a script, for example whether it is an alias before using it.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course