Lesser known Linux Commands: type

July 28, 2009

type: This is a simple and very useful shell built-in command. It will tell us location of an executable file.  Type searches through $PATH, returns the pathname of the file. e.g
$ type sudo
sudo is /usr/bin/sudo

locate and which are similar command. However type differs in following respects
a.It is shell built in and hence fast.
b.It searches only $PATH
c.Searches for executable files only

Following timings are returned from system :
$ time type sudo
sudo is /usr/bin/sudo

real    0m0.000s
user    0m0.000s
sys     0m0.000s

$ time which sudo

real    0m0.004s
user    0m0.004s
sys     0m0.000s

$ time locate sudo

real    0m0.201s
user    0m0.192s
sys     0m0.004s

As can be seen above the execution time is remarkably less for type.
type is preferred to other in following conditions
a.Want to search in $PATH
b.Want to search only executables
type is not useful in following conditions
a.search whole file system
b.search on partial name.
c.search for non-executable files