Linux Type Command

Updated on

3 min read

type Command

The type command is used to display information about the command type. It will show you how a given command would be interpreted if typed on the command line.

In this article, we will explain how to use the Linux type command.

How to Use the type Command

type is a shell builtin in Bash and other shells like Zsh and Ksh. Its behavior may be slightly different from shell to shell. We will cover the Bash builtin version of type.

The syntax for the type command is as follows:

sh
type [OPTIONS] FILE_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 arguments 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)

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
    builtin
  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:

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 option is used, the type command will include aliases and functions, only if the -p option is not used.

Other type command options

The -p option will force type to return the path to the command only if the command is an executable file on the disk:

For example, the following command will not display any output because the pwd command is a shell builtin.

Terminal
type -p pwd

Unlike -p, the uppercase -P option tells type to search the PATH for an executable file on the disk even if the command is not file.

Terminal
type -P pwd
output
pwd is /bin/pwd

When the -f option is used, type will not look up for shell functions, as with the command builtin.

Conclusion

The type command will show you how a specific command will be interpreted if used on the command line.

If you have any questions or feedback, please leave a comment below.