type Command in Linux: Show Command Type and Location

By 

Updated on

4 min read

type Command

The type command shows how the current shell would interpret a name entered on the command line. Depending on the shell, it can identify aliases, functions, builtins, keywords, and executable files.

This article explains how to use the type builtin, with Bash examples and notes where Zsh and other popular shells behave differently.

How to Use the type Command

type is a shell builtin in Bash, Zsh, and Ksh, but the supported options and output format are not identical across shells. The examples below use Bash syntax, and option availability should be checked in your current shell with help type, type --help, or the shell documentation.

The syntax for the type command is as follows:

txt
type [OPTIONS] NAME...

For example, to find the type of the wc command , you would type the following:

Terminal
type wc

The output will be something like this:

output
wc is /usr/bin/wc

You can also provide more than one argument to the type command:

Terminal
type sleep head

The output will include information about both sleep and head commands:

output
sleep is /bin/sleep
head is /usr/bin/head

Command Types

The option -t tells type to print a single word describing the type of the command which can be one of the following:

  • alias (shell alias)
  • function (shell function)
  • builtin (shell builtin)
  • file (disk file)
  • keyword (shell reserved word)

The exact wording may differ between shells. For example, Zsh can report command where Bash reports file.

Here are a few examples:

  1. Alias

    Terminal
    type -t grep

    In my system grep is aliased to grep --color=auto:

    output
    alias
  2. Function

    Terminal
    type -t rvm

    rvm is a tool (function) for installing, managing, and working with multiple Ruby environments:

    output
    function
  3. Builtin

    Terminal
    type -t echo

    echo is a shell builtin in Bash and other shells like Zsh and Ksh:

    output
    builtin
  4. File

    Terminal
    type -t cut

    cut is an executable file:

    output
    file
  5. Keyword

    Terminal
    type -t for

    for is a reserved word in Bash:

    output
    keyword

Display all locations that contain the command

To print all matches, use the -a option:

This option is supported by Bash and Zsh, but the order and wording of the results may differ.

Terminal
type -a pwd

The output will show you that pwd is a shell builtin but it is also available as a standalone /bin/pwd executable:

output
pwd is a shell builtin
pwd is /bin/pwd

When -a is used without -p, type can include aliases and functions in addition to executable files.

Additional Options

In Bash and Zsh, the -p option prints the path only when the resolved name is an executable file on disk:

For example, this command may print nothing because pwd is usually resolved as a shell builtin.

Terminal
type -p pwd

In Bash, the uppercase -P option tells type to search PATH for an executable file on disk even when the name also resolves to a builtin or function. This option may not be available in all shells.

Terminal
type -P pwd
output
/bin/pwd

The -f option tells type to skip shell functions during lookup. Support for this option may vary by shell.

Quick Reference

CommandDescription
type nameShow how a name would be interpreted
type name1 name2Check multiple names at once
type -t namePrint the type word only (alias, function, builtin, file, keyword)
type -a nameShow all locations that match the name
type -p namePrint the path only if it is a disk file
type -P nameForce a PATH search even for builtins
type -f nameIgnore shell functions when looking up the name

FAQ

What is the difference between type and which?
which searches only PATH for executable files. type is a shell builtin that also identifies aliases, functions, keywords, and other builtins — making it more complete for understanding how the shell will resolve a name.

What does it mean when type says a command is a builtin?
The command is handled directly by the shell without forking a new process. Examples include echo, cd, pwd, and type itself.

Why does type -p return nothing for some commands?
-p only prints a path when the command is an executable file on disk. Builtins, functions, aliases, and keywords produce no output with -p.

Does the type command behave the same in Bash and Zsh?
No. type is a shell builtin, so supported options and output format can differ between Bash, Zsh, and other shells. If you need a portable way to check whether a command exists in a script, prefer command -v name.

Can I use type in a script to check if a command exists?
Yes. Use type -P command or type command > /dev/null 2>&1 and check the exit code. Exit code 0 means the command was found; a non-zero exit code means it was not.

Conclusion

The type command shows how the shell will interpret a given name — whether it resolves to a builtin, alias, function, keyword, or an executable on disk. It is more thorough than which for understanding shell name resolution.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page