Are you a Linux user who wants to be more familiar with the command line interface? Then the
type command is something you need to know about. This command allows you to obtain information about other commands that you may use on your system. Understanding how to use the
type command can make you more efficient and productive when working with Linux.
In this article, we’ll cover everything you need to know about the Linux
type command. We’ll explain what it is and how it works, and provide examples of how to use it. By the end of this article, you’ll be able to use the
type command with ease.
How to Use the type Command
type command is a built-in function present in shells such as Bash, Zsh, and Ksh. While its functionality may vary slightly depending on the shell, we will focus on the Bash implementation of this command.
To use the
type command, use the following syntax:
type [OPTIONS] FILE_NAME...
To determine the type of the
wc command, you could input the following command as an illustration:
The resulting output will appear in a similar format:
Output: wc is /usr/bin/wc
The type command allows for the provision of multiple arguments as well:
type sleep head
Information regarding both the sleep and head commands will be included in the output:
Output: sleep is /bin/sleep head is /usr/bin/head
If you use the -t flag with the “type” command, it will display a word that indicates the type of command. The possible types are:
- Alias (a shell alias)
- Function (a shell function)
- Builtin (a shell builtin)
- File (a file on disk)
- Keyword (a reserved word in the shell)
Here are some examples:
type -t grep
I have set an alias for
grep in my system, so that it runs with the
type -t rvm
rvm is a utility (feature) designed to facilitate the installation, administration, and utilization of numerous Ruby environments:
type -t echo
The “echo” command is a built-in function in various shells such as Bash, Zsh, and Ksh:
type -t cut
An executable file is known as a “
type -t for
In Bash, the word “
for” is a reserved keyword:
Display all locations that contain the command
To display all matches, utilize the -a flag:
type -a pwd
The output will show you that
pwd is a shell builtin but it is also available as a standalone
Output: pwd is a shell builtin pwd is /bin/pwd
-p option is not utilized, the type command will encompass aliases and functions solely when the
-a option is employed.
Other type command options
If the command exists as an executable file on the disk, utilizing the
-p flag will oblige the
type command to exclusively return the path to the command:
pwd command, being a shell builtin, won’t produce any output when executed, as demonstrated by the following command.
type -p pwd
-P option in uppercase instructs the “
type” command to scan through the
PATH directories in search of an executable file, even if the command is not a regular file.
type -P pwd
Output: pwd is /bin/pwd
-f flag is employed, the
type command will refrain from searching for shell functions, in line with the behavior of the command built-in.
In conclusion, utilizing the
type command on the command line can provide valuable insight into how a specific command will be interpreted. This can aid in understanding the functionality and potential outcomes of the command before executing it.
If you have any further inquiries or feedback regarding this topic, please do not hesitate to leave a comment below. Stay informed and efficient with your command line usage.