In this post we are explaining about type command with examples. In Linux system, type command is used for displaying information about command types. It displays if command is an alias,shell function, shell builtin, disk file, or shell reserved word.
You can use type command with other command names also.
With the help of type command you can also identify about command if it is Internal or External command.
Note: The type
command will show output only when the command/executable name is available or installed in Linux System.
SYNOPSIS
type [-afptP] name [name ...]
Try the type command without giving any argument and try to see the result. For example let’s try on cd
command
user1@server01:~$ type cd cd is a shell builtin user1@server01:~$
As per the output in above section, it confirms the cd command is Internal command (or in other words, shell builtin command)
Description Of type Command
-t option :
It will show a single word or string.It tells a command or name is an alias, shell reserved word, function, builtin, or disk file(external command).
In case command is not found, nothing will be printed as output.When we check exit status of command, it will be false.
Example :
root@tuxworld:~# type -t ls alias root@tuxworld:~# root@tuxworld:~# type -t date file root@tuxworld:~# root@tuxworld:~# type -t declare builtin root@tuxworld:~# root@tuxworld:~# type -t rvm function root@tuxworld:~#
-p option :
The command of the disk file that would be executed. In other words, absolute path of command.
Example:
root@tuxworld:~# type -p date /bin/date root@tuxworld:~#
-P option :
Force a PATH search for each command/NAME, even if it is an alias,builtin, or function, and returns the name of the disk file that would be executed.
(We can get PATH environment value by using command echo $PATH
)
NOTE: In below example, date command was searched in all directories listed in PATH(Environment set). And found the date command in /bin
root@tuxworld:~# type -P date /bin/date root@tuxworld:~# root@tuxworld:~# echo $PATH /usr/local/rvm/gems/ruby-2.1.0/bin:/usr/local/rvm/gems/ruby-2.1.0@global/bin:/usr/local/rvm/rubies/ruby-2.1.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/rvm/bin root@tuxworld:~#
-a option :
It display all locations have command or NAME .
It includes aliases, builtins, and functions (only in case , if -p option is not used )
Example :
root@tuxworld:~# type -a echo echo is a shell builtin echo is /usr/sbin/echo echo is /bin/echo root@tuxworld:~#
-f option :
The -f option,suppress shell function lookup.
Example.
type -f rvm
Note: rvm command is a user defined function.(what is rvm? Read More) When we use type -a rvm
,the output will show functions defined. In above example, -f option will suppress the function.