Find out if a command resolves to an alias, disk file, shell function, built-in command, or reserved word , Use the type
Performing My Bidding
When we open a terminal window and send commands to our Linux computer, we seldom stop thinking about which software components in the operating system respond to our commands and execute them for us. We type in the command, get the result and continue our work.
If we know how to run the commands, we can better understand how our Linux or other Unix-like operating system is built. A look under the bonnet can make us an informed driver.
The instructions we send to the command line are divided into one of the following categories:
- alias : A command defined by the user (or system) that causes other, usually lengthy, or other complex command sequences take place.
- disk file : A binary executable file such as
/ usr / bin / top.
- Shell function : A custom (or system-defined) function that can be used on the command line or included in scripts.
- Built-in command : A command executed by the shell itself, z
- Reserved word : A word reserved by the shell, e.g. B.
elif. They are also referred to as keywords.
command of type indicates which category a Linux command belongs to. Here's a quick guide to understanding the command output.
The Command Type
Let's review a few short examples for each command category.
date is an executable disk file.
ls is an alias, wrapping the underlying command
ls to default the option
- color = auto to use.
lowdown is a user-defined function set up for the commuter with whom this item was researched. It provides a quick overview of some system resources. It is a combination of
pwd is a built-in Bash shell command.
] The elif command is a reserved word in the bash shell.
Using Multiple Commands
You can enter multiple commands
to identify them at the same time.
Give a Date Top ls
The option -t
None of the options that you enter
-t "scarce", you will not be very wrong. It reduces the responses of
type to single word answers.
Type -t date
Type -t Pwd
Type -t Lowdown
The option -a
Let's call this Option the option "all". All the positions where the command is located are listed. Note that this option does not work if you also use the option
For example, if you have an alias with the same name as the underlying command, you can get information about the alias and the command.
Type -a ls
-f enforces that does not search for user-defined functions or system-defined functions. Think of this option as a "feature search". Note that if the command is a function,
type reports that the command can not be found.
Type -f top
type -f lowdown
If you have the option
type only searches directories in $ PATH. So we can call this option "path". Note that this option uses a capital letter "P".
Type -P date chmod adduser
If you use the option
only if the command is a disk file. Note that this option uses a lowercase letter "p".
Type -p mount
Type -p ls
Type -p -a ls
type There is no answer for
ls is an alias and not a disk file.
-a option, so that the
type searches for all instances of the command
ls lists the underlying disk file that the
ls -Alias uses of.
That was nice and simple, but still lighting.
We tend to think of anything we put in a terminal window as a "command" and leave it at that. In fact, commands in the Linux system are implemented in several ways. And with
type you can find out which one is involved.