Type command tutorial with examples for beginners

Team type used to find information about commands in Linux. As the name suggests, you can easily find a given command, whether it is an alias, builtin shell, file, function, or keyword using the “type” command. Also, you can find the real path of the command. Why would anyone need to find a command type? For example, if you will be working often on a public computer, some guys may accidentally or deliberately create an alias for a specific Linux command to perform an unwanted operation, such as “Alias ​​ls = rm -rf /”… Thus, it is always a good idea to check them before something happens. This is where the type command comes in handy.

Let me show you some examples.

Run the type command without any flags.

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

As you can see in the above output from the “ls” command, the alias was “ls –color = auto”. It is, however, harmless. But just think if the ls command under an alias is something dangerous. You don’t want that, do you?

You can use the flag -tto find only the Linux command type. For example:

$ type -t ls
alias
$ type -t mkdir
file
$ type -t pwd
builtin
$ type -t if
keyword
$ type -t rvm
function

This command simply displays the type of the command, that is, the alias. It does not display aliases for this command. If the command is not found, then you will not see anything in the terminal.

Another useful advantage of the type command is that we can easily find out the absolute path to a given Linux command. To do this, use the flag -pas shown below.

$ type -p cal
/usr/bin/cal

This is similar to the ‘which ls’ command. If the given command has an alias, nothing will be printed.

To display all information about a command, use the flag -a

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

As you can see, the -a flag shows the type of the given command and its absolute path. See man pages for more details.

$ man type

I hope this article helps you.

Sidebar