Linux type Command: Identify Commands, Functions, Aliases, or Files
The type command in Linux is used to describe some name provided as a parameter, such as a bash builtin, program, function, alias, or file. If no name is provided, it does nothing.
The type command is commonly used to find information about a Linux command. You can easily discover if the given command is an alias, builtin, file, function, or keyword using the "type" command. Additionally, you can also find the actual path of the command.
Why would someone need to find the "type" of a command? For example, if you happen to work on a shared computer frequently, someone may intentionally or accidentally create an alias for a certain Linux command to perform an unwanted operation, for example "alias ls = rm -rf/". Therefore, it's always a good idea to inspect them before something worse happens. This is where the type command comes in handy.
Examples:
$ type bashbash is /usr/bin/bash
$ type llll is aliased to `ls -l --color=auto'
$ type for
for is a shell keyword
$ type -t ls
alias
$ type -t mkdir
file
$ type -t pwd
builtin
$ type -t if
keyword
$ type -t rvm
function
Another useful advantage of the type command is that we can easily discover the absolute path of a given Linux command. To do this, use the "-p" option as shown below:
$ type -p cal
/usr/bin/cal
This example is similar to the 'which ls' command. If the given command is an alias, nothing will be printed.
To display all information about a command, use the "-a" option:
$ type -a ls
ls is aliased to `ls --color=auto'
ls is /usr/bin/ls
ls is /bin/ls
Conclusion
If you need to know about a given command, you can use type to describe whether the command is a shell builtin, a program, or an alias.
Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.
Did you like it? Share
That was just one piece. The course teaches the whole path — from your first command to exam day.