Linux type command (describes something) [Basic Guide]

The type command in Linux is used to describe a name entered as a parameter, such as an internal bash command, program, function, nickname, or file. If no name is provided, it doesn’t do anything.

The type command is generally used to find out information about a Linux command. You can easily find out if the command provided is an alias, embedded shell, file, function, or keyword using the “type” command. In addition, you can also find the actual path of the command.

Why would someone need to find the command “type”? For example, if you happen to work on a frequently shared computer, someone may intentionally or accidentally create an alias for a particular Linux command to perform an unwanted operation, for example “alias ls = rm -rf/”. So it’s always a good idea to inspect them before anything worse happens. This is where the type command comes in handy.

Examples:

$ type bash bash is /usr/bin/bash

$ type ll ll 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

The other 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 aliased, nothing will be printed.

To view all information about a command, use the “-a” option:

$ type -to 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 particular command, you can use the type to describe whether the command is internal to the shell, a program, or an alias.

Learn much more about Linux in our online course. You can register 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

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Need help?