Fatmawati Ahmad Zaenuri / Shutterstock.com

Find out if a command converts to an alias, a disk file, a shell function, a builtin command, or a reserved word. Use type to learn how your Linux commands are executed and better understand your system.

Make my trades

When we open a terminal window and start issuing commands to our Linux computer, we rarely stop to consider what software components in the operating system are responding to our commands and executing them for us. We recruit a team, get a result, and move on to our workload.

Knowing how commands are executed gives us a better understanding of how our Linux or other Unix-like operating system works. Looking under the hood can make us a more informed driver.

The instructions we issue for the command line fall into one of the following categories:

  • Nickname : A user (or system) defined command that causes other, usually long or complex, sequences of commands to be executed.
  • Disk file : a binary executable such as /usr/bin/top .
  • shell function : A user (or system) defined function that can be used on the command line or included in scripts.
  • built-in team : command executed by the shell itself, e.g. pwd .
  • reserved word : a word reserved by the shell, e.g. if and elif . They are also called keywords.

Team type tells us which category any of the Linux commands belongs to. Here is a quick guide to understanding the output of the command.

Type Command

Let’s look at a few quick examples for each of the command categories.

  введите дату 

enter date in terminal window

Team date is an executable file on disk.

  типа лс 

type ls in terminal window

Team ls is an alias containing the base command ls to use the parameter --color=auto default.

  тип lowdown 

type lowdown in terminal window

Team lowdown is a custom feature that was configured on the commuter area used for this article’s research. This provides a quick snapshot of some system resources. It’s a combination whoami , w , free and df .

  типа pwd 

type pwd in a terminal window

Team pwd is a built-in command of the Bash shell.

  тип элиф 

type elif in terminal window

Team elif is a reserved word in the Bash shell.

Using multiple commands

You can specify multiple commands for simultaneous identification.

  введите дату сверху ls 

enter date top ls in terminal window

Option -t

None of the parameters it takes type has no names. This way we can get our book of names and baptize them ourselves. If you think that the setting -t means «short», you can’t go wrong. This reduces responses from type to one word answers.

  введите -t дата 
  наберите -t pwd 
  введите -t lowdown 

demonstrating the -t type option in a terminal window

Option -a

Let’s call this option «all». It lists all the locations where the team is located. Please note that this setting not will work if you also use the parameter -p .

For example, if you have an alias with the same name as the main command, you can get information about the alias and the command.

  введите -a ls 

demonstrating the -a type option in a terminal window

Option -f

Option -f makes type not search for user or system functions. Think of this option as «feature search». Please note that if the command is function, type will report that the command could not be found.

  введите -f top 
  тип -f lowdown 

demonstrating the type -f option in a terminal window

Option -P

If you use the option -P , type will only look for directories in $PATH . So we can call this option «path». Note that this option uses a capital «P.»

  введите -P дата chmod adduser 

type -P date chmod adduser in terminal window

Option -p

If you use the option -p , type will only respond if the command is a file on the hard drive. Note that this option uses a lowercase «r».

  введите -p mount 
  введите -p ls 
  введите -p -a ls 

demonstrating type option -p in terminal widow

type gives no answer for ls because ls is an alias, not a disk file.

But if we enable the option -a to type looked through all instances of the command ls it lists the underlying disk file that uses the alias ls .

Summary

It was beautiful and simple, but still illuminating.

We tend to think of anything we type in a terminal window as a «command» and we leave it at that. But in fact, commands are implemented in various ways on a Linux system. And type lets you know which one it is.

Похожие записи