What is the function of the “type” command in Linux?

In Linux, the ‘type’ command is used to display the type of a specified command. It can determine whether the given command is an external command (executable file), an internal command (shell’s built-in command), or a command alias (a defined alias for a command). This is helpful for understanding the available commands in the system and how commands are resolved and executed.

There are several ways to use the type command:

  1. Display the type and location of a command by typing . This will show the type of the given command, such as “external command,” “internal command,” or “alias,” as well as the path of the command. For example, typing type ls will show ls is aliased to ‘ls –color=auto’, indicating that ls is an alias command that points to ls –color=auto.
  2. Display command definition by using type -a . This will show all definitions of the given command. If the command has multiple definitions or aliases, they will be displayed in the order of their definitions. For example, type -a ls will display:
  3. ls is assigned to the command ‘ls –color=auto’
    ls is located in /usr/bin/ls
  4. It indicates that ls has an alias and an external command definition.
  5. Only display the alias of a command: type -t
    This will show only the type of the given command, without displaying the location of the command. If the command is an alias, it will display as “alias.” If the command is an external command, it will display as “file.” If the command is an internal command, it will display as “builtin.” For example, type -t ls will show alias, indicating that ls is an alias.

In Linux, the ‘type’ command is used to find out the type and location of a command, as well as to display its definition and aliases. This is very helpful for understanding how commands are executed and what commands are available in the system.

bannerAds