It is nothing fancy, but there are situations where it is beneficial to know how to identify and inspect command before execution.
This can be achieved by using type
shell builtin command.
$ type ls ls is aliased to `ls --color=auto'
$ type quote quote is a function quote () { local quoted=${1//\'/\'\\\'\'}; printf "'%s'" "$quoted" }
$ type lvm lvm is /sbin/lvm
Use -t
argument to identify command type, which is one of alias
, reserved keyword
, function
, builtin
, file
.
$ type -t ls alias
$ type -t case keyword
$ type -t quote function
$ type -t type builtin
$ type -t tar file
Use -p
argument to print filename of the command to be executed.
$ type -p tar /bin/tar
Use -P
argument to force search for the filename of the command to be executed. It is useful in several edge cases (command is alias
, function
, builtin
).
$ type -P ls /bin/ls
$ type -P pwd /bin/pwd
Use -a
argument to print all information at once.
$ type -a ls ls is aliased to `ls --color=auto' ls is /bin/ls
$ type -a pwd pwd is a shell builtin pwd is /bin/pwd