How to inspect command before execution

It is nothing fancy, but there are situations where it is very useful 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   
$ type -t case
$ type -t quote
$ type -t type
$ type -t tar

Use -p argument to print filename of the command to be executed.

$ type -p tar

Use -P argument to force search for filename of the command to be executed. It is useful in several edge cases (command is alias, function, builtin).

$ type -P ls
$ type -P 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
Milosz Galazka's Picture

About Milosz Galazka

Milosz is a system administrator working for a successful Polish company and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland