How To Use Type Command.
In this article, we will explain how to use the Linux 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.
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:
For example, to find the type of the wc command , you would type the following:
The output will be something like this:
You can also provide more than one arguments to the type command:
The output will include information about both sleep and head commands:
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:
In my system grep is aliased to grep –color=auto:
rvm is a tool (function) for installing, managing, and working with multiple Ruby environments:
echo is a shell builtin in Bash and other shells like Zsh and Ksh:
cutis an executable file :
for is a reserved word in Bash:
Display all locations that contain the command
To print all matches, use the -a option:
The output will show you that pwd is a shell builtin but it is also available as a standalone /bin/pwd executable:
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.
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.
When the -f option is used, type will not look up for shell functions, as with the command builtin.
The type command will show you how a specific command will be interpreted if used on the command line.