type command in Linux with Examples
Last Updated :
23 Sep, 2024
The type command in Linux is a useful utility for identifying how the shell will interpret a given command. It provides information on whether a command is a shell built-in, external binary, function, or alias, helping users understand the source of the command and its behavior. The command is particularly helpful when troubleshooting or exploring system utilities, as it reveals whether a command is being executed as an alias, keyword, or a binary file from the disk.
Syntax
type [Options] command names
Basic ‘type’ command Example
Key Options of the type Command
1. -a: Show All Locations (Aliases, Keywords, Functions, Executable Files)
This option is used to find out whether it is an alias, keyword or a function and it also displays the path of an executable, if available.
Example:
type -a pwd
2. -t: Display a Single Word Indicating Command Type
The ‘-t’ option will return a single word that describes the type of the command. It simplifies the output by focusing only on the category of the command: alias, keyword, builtin, function, or file.
Example:
type -t pwd
type -t cp
type -t ls
type -t while
- alias: if command is a shell alias
- keyword: if command is a shell reserved word
- builtin: if command is a shell builtin
- function: if command is a shell function
- file: if command is a disk file
3. -p: Display the Path to the Executable File
This option displays the name of the disk file which would be executed by the shell. It will return nothing if the command is not a disk file.
Example:
type -p dash
If dash exists as an executable on the disk, it shows the path where it’s located.
Conclusion
The ‘type’ command in Linux is a versatile tool that helps users and system administrators gain insights into how commands are interpreted by the shell. ‘type’ makes it easy to understand the source of a command’s behavior, whether you’re trying to figure out if a command is a built-in or external executable, or debugging an alias.
type command in Linux – FAQs
What does the ‘type’ command do in Linux?
The type command in Linux is used to display how the shell interprets a given command. It helps identify whether a command is a built-in function, an alias, a keyword, or an external binary file.
How do I use the type command?
To use the type command, simply enter:
type <command>
What are some common options for the type command?
- -a: Displays all possible interpretations (alias, keyword, built-in, executable).
- –t: Outputs a single word indicating the type (alias, keyword, built-in, function, file).
- -p: Displays the path to the executable file if the command is an external binary.
What’s the difference between type and which commands?
While both commands are used to find details about a command, they serve different purposes:
- type: Provides detailed information about whether a command is an alias, built-in, or external binary.
- which: Only shows the path to the executable of an external command, if available.