TYPE is a Linux command which helps to identify the type of the input command if it is an alias, built-in, function, or keyword. You can also pass multiple commands as the input parameters.
All the arguments to this command are optional.
Syntax
type [-afptP] name [name ...]
Options
[afptP]
-a - display all locations containing an executable named NAME; includes aliases, builtins, and functions, if and only if the '-p' option is not also used -f - suppress shell function lookup -P - force a PATH search for each NAME, even if it is an alias, builtin, or function, and returns the name of the disk file that would be executed -p - returns either the name of the disk file that would be executed or nothing if `type -t NAME' would not return `file'. -t - output a single word which is one of `alias', `keyword', `function', `builtin', `file' or `', if NAME is an alias, shell reserved word, shell function, shell builtin, disk file, or not found, respectively
Name – Command name to be interpreted.
Exit Status – Returns success if all of the NAMEs are found; fails if any are not found.
Type Command(Examples)
In Linux, Unix, and Unix-alike system command may an alias, shell built-in, file, function, or keyword. So how to find the type of command you are running on the shell.
Consider pwd command, is it shell built-in or function?
The shell provides a unique command type to find out this. Open the Linux terminal and run the command as shown below.
$ type -a pwd pwd is a shell builtin
The output tells us that pwd is shell built-in.
What about the ls command?
type ls ls is aliased to `ls --color=auto'
ls is an alias.
The type itself is a shell built-in. You can find this by running on itself.
$ type type type is a shell builtin
Now, here we will cover all options along with Examples,
1. -a option displays all locations containing an executable named NAME along with its type.
$ type -a pwd pwd is a shell builtin pwd is /bin/pwd
You can also pass multiple names of the command as input to this command.
$ type -a pwd wc pwd is a shell builtin pwd is /bin/pwd wc is /usr/bin/wc wc is /usr/bin/wc
2. -f option suppresses the shell function lookup.
$ type -f pwd pwd is a shell builtin
3. -p returns the name of the disk file that would be executed along with the complete path for alias, built-in, or function.
$ type -p wc /usr/bin/wc
4. -t option simply returns type like builtin, function, alias, etc
$ type -t pwd builtin
Summary
So, we covered the basic working of the Linux Type command with examples. At any point of time, if you want help, just run man or help type on the terminal.
Refer to this online manual for the command.