type
From Initq
The type command display how a name would be interpreted as a command. Where applicable type will display the name's path. Possible command types are:
- shell built-in
- function
- alias
- hashed command
- keyword
[alibaba@ohnonono ~]$ type test test is a shell builtin [alibaba@ohnonono ~]$ type cp cp is /bin/cp [alibaba@ohnonono ~]$ type bmw -bash: type: bmw: not found [alibaba@ohnonono ~]$ type type type is a shell builtin
Flags
- If the -t option is used, `type' outputs a single word which is one of alias, keyword, function, builtin, file etc
- If the -p flag is used, `type' either returns the name of the disk file that would be executed, or nothing if `type -t NAME' would not return `file'.
- If the -a flag is used, `type' displays all of the places that contain an executable named `file'. This includes aliases, builtins, and functions, if and only if the -p flag is not also used.
- The -f flag suppresses shell function lookup.
- The -P flag forces a PATH search for each NAME, even if it is an alias, builtin, or function, and returns the name of the disk file that that would be executed.
If you want to find out whether a command is aliased then you can do the following:
qais:/etc# alias ls='ls -la' qais:/etc# type ls ls is aliased to `ls -la' qais:/etc# type -t ls alias qais:/etc# type -P ls /bin/ls qais:/etc# unalias ls qais:/etc# type ls ls is hashed (/bin/ls)
First command will create an alias for ls command. then when we use type we get the information that ls is alised and with what is it aliased. With the -t flag we just get one word answer. -P gives us the path. We will unalias the command and run type ls again. Now we are told that ls is "hashed", i.e., the shell has an internal record for the quick access to the location of the ls commad.