LinuxCommandLibrary

type

Identify command type

TLDR

Display the type of a command

$ type [command]
copy

Display all locations containing the specified executable (works only in Bash/fish/Zsh shells)
$ type -a [command]
copy

Display the name of the disk file that would be executed (works only in Bash/fish/Zsh shells)
$ type -p [command]
copy

Display the type of a specific command, alias/keyword/function/builtin/file (works only in Bash/fish shells)
$ type -t [command]
copy

SYNOPSIS

type [-aftpP] name [name ...]

PARAMETERS

-a
    Display all occurrences of name. This option overrides the -t and -p options.

-f
    Suppresses shell function and builtin command lookup.

-t
    Output only one word describing the type of each name. Possible values are: alias, keyword, function, builtin, or file. If name is not found, nothing is printed.

-p
    Return the path name which would be used if name were invoked as a command. If name is a shell builtin command, it returns nothing. Overrides the -t option.

-P
    Forces a search for name using the PATH environment variable, even if name is a shell builtin or reserved word. Useful to determine if an external command shadows a builtin.

DESCRIPTION

The type command in Linux is a built-in shell command used to determine how a command name would be interpreted by the shell. It displays whether a command is an alias, a keyword, a function, a built-in, or a file on disk (which would be found via the PATH environment variable). It helps users understand the nature of a command before executing it, preventing unexpected behavior. type is invaluable for scripting and debugging, particularly when dealing with command-line arguments that might have different meanings depending on the command's type.

By default, the command returns information for each name provided as argument.

CAVEATS

The type command provides information based on the *current* shell environment. Aliases, functions, and the PATH variable can be modified within a shell session, so the output might differ across shell sessions or scripts.

EXIT STATUS

The type command returns an exit status of 0 if all names are found; non-zero if any name is not found.

EXAMPLES

type ls
might output: ls is /bin/ls

type -a ls
might output: ls is aliased to `ls --color=auto'
ls is /bin/ls

HISTORY

The type command has been a standard part of Unix-like operating systems for a long time, originating from the early days of shell scripting. Its primary purpose has always been to provide a way to introspect the nature of commands within the shell environment. The command's functionality has remained relatively consistent throughout its history, serving as a fundamental tool for understanding command resolution and debugging shell scripts.

SEE ALSO

which(1), whereis(1), whatis(1)

Copied to clipboard