Home FAQ The Type Command Tutorial With Examples For Beginners
Type command

The Type Command Tutorial With Examples For Beginners

By sk

The Type command is used to find out the information about a Linux command. As the name implies, you can easily find whether the given command is an alias, shell built-in, file, function, or keyword  using "type" command. Additionally, you can find the actual path of the command too.  Why would anyone need to find the command type? For instance, if you happen to work on a shared computer often, some guys may intentionally or accidentally create an alias to a particular Linux command to perform an unwanted operation, for example "alias ls = rm -rf /". So, it is always good idea to inspect them before something worse happen. This is where the type command comes in help.

Let me show you some examples.

The Type Command Tutorial With Examples For Beginners

Run the Type command without any flags.

$ type ls
ls is aliased to `ls --color=auto'

As you can see in the above output, the "ls" command has been aliased to "ls --color-auto". It is, however, harmless. But just think of if the ls command is aliased to something dangerous. You don't want that, do you?

You can use -t flag to find only the type of a Linux command. For example:

$ type -t ls
$ type -t mkdir
$ type -t pwd
$ type -t if
$ type -t rvm

This command just displays the type of the command, i.e alias. It doesn't display what is aliased to the given command. If a command is not found, you will see nothing in the terminal.

The another useful advantage of type command is we can easily find out the absolute path of a given Linux command. To do so, use -p flag as shown below.

$ type -p cal

This is similar to 'which ls' command. If the given command is aliased, nothing will be printed.

To display all information of a command, use -a flag.

$ type -a ls
ls is aliased to `ls --color=auto'
ls is /usr/bin/ls
ls is /bin/ls

As you see, -a flag displays the type of the given command and its absolute path.

So, what is the type of "type" command itself?

$ type type
type is a shell builtin

For more details, refer the help section.

$ help type

Suggested read:

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

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

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More