The type command is used to show information about the command type
and how its argument would be interpreted if typed on the command line. It is also used to find out whether it is built-in or external binary file. In this article, we will explain how to use the Linux type
command.
How to Use the type
Command
Below is the basic syntax for thetype
command:
type [OPTIONS] FILE_NAME...
For example, to find the type
of the cd command, you would type
the following:
type cd
It will show output as following:
cd is a shell builtin
You can pass the multiple arguments to the type
command by space separated:
type sleep cd
sleep is /bin/sleep cd is a shell builtin
Command Options
Use the option -t
with type to find out whether it is an alias, keyword or a function, it can be one of the following single word output:
- alias
- function
- builtin
- file
- keyword
Following are the examples:
1. Alias
type -t grep
Here ls is aliased to ls --color=auto
:
alias
2. Function
type -t rvm
rvm
is a tool (function) for installing, managing, and working with multiple Ruby environments:
function
3. Builtin
type -t cd
cd
is a shell builtin in Bash and other shells like Zsh and Ksh:
builtin
4. File
type -t cut
cut is an executable file:
builtin
5. Keyword
type -t while
while
is a reserved word in Bash:
keyword
Display all locations that contain the command
Option -a
is used to display all matches and the path of an executable, if available.
type -a pwd
pwd is a shell builtin pwd is /bin/pwd
In above output showing that pwd
is shell builtin and it is also available as a standalone /bin/pwd
executable.
Other type
command options
Use the -p
option with to force type
command to print the path to the command 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.
type -p pwd
The uppercase -P
option tells type
to search the PATH for an executable file on the disk even if the command is not file.
type -P pwd
pwd is /bin/pwd
Type command will not look up for shell functions when the -f
option is used.
Conclusion
The type
command will show you information about specific command type and how it will interpreted if used on the command line.
If you have any questions or feedback, please leave a comment below.