linux type命令
Find out if a command resolves to an alias, a disk file, a shell function, a built-in command, or a reserved word. Use type
to discover how your Linux commands are executed and understand your system better.
找出命令是否解析为别名,磁盘文件,shell函数,内置命令或保留字。 使用type
来发现Linux命令的执行方式并更好地了解您的系统。
做我的竞标 (Do My Bidding)
When we open a terminal window and start issuing commands to our Linux computer, we rarely stop to think what software components within the operating system are reacting to our commands and carrying them out for us. We type the command, get the result, and move on with our workload.
当我们打开终端窗口并开始向Linux计算机发出命令时,我们很少停止思考操作系统中的哪些软件组件正在对我们的命令做出React并为我们执行这些命令。 我们键入命令,获取结果,然后继续进行工作。
Knowing how the commands are carried out gives us a better understanding of the way our Linux or other Unix-like operating system is constructed. Having a peek beneath the hood can make us a more informed driver.
了解命令的执行方式可以使我们更好地了解Linux或其他类似Unix的操作系统的构建方式。 深入了解引擎盖可以使我们成为更有见识的驾驶员。
The instructions we issue to the command line are in one of the following categories:
我们发布给命令行的指令属于以下类别之一:
Alias: A user (or system) defined command that causes other, usually long-winded or complex, command sequences to take place.
别名:用户(或系统)定义的命令,它导致其他通常冗长或复杂的命令序列发生。
Disk file: A binary executable file, such as
/usr/bin/top
.磁盘文件:二进制可执行文件,例如
/usr/bin/top
。Shell function: A user (or system) defined function that can be used on the command line or included in scripts.
Shell函数:用户(或系统)定义的函数,可以在命令行上使用或包含在脚本中。
Builtin command: A command that is carried out by the shell itself, such as
pwd
.内置命令:由外壳本身执行的命令,例如
pwd
。Reserved word: A word that is reserved by the shell such as
if
andelif
. They are also called keywords.保留字:shell保留的一个字,例如
if
和elif
。 它们也称为关键字。
The type
command tells us which category any of the Linux commands belongs to. Here’s a quick tutorial to understanding the command’s output.
type
命令告诉我们任何Linux命令属于哪个类别。 这是帮助您理解命令输出的快速教程。
类型命令 (The type Command)
Let’s rattle through some quick examples, for each of the command categories.
让我们仔细研究一下每个命令类别的一些简单示例。
type date
The date
command is an executable disk file.
date
命令是可执行的磁盘文件。
type ls
The ls
command is an alias, wrapping the underlying ls
command to use the --color=auto
option by default.
ls
命令是一个别名,默认情况下将基础ls
命令包装为使用--color=auto
选项。
type lowdown
The lowdown
command is a user-defined function that was set up on the commuter used to research this article. It provides a quick snapshot of some system resources. It is a combination of whoami
, w
, free
and df
.
lowdown
命令是用户定义的功能,该功能是在用于研究本文的通勤者上设置的。 它提供了一些系统资源的快速快照。 它是whoami
, w
, free
和df
。
type pwd
The pwd
command is a built-in command of the Bash shell.
pwd
命令是Bash shell的内置命令。
type elif
The elif
command is a Bash shell reserved word.
elif
命令是Bash shell保留字。
使用多个命令 (Using Multiple Commands)
You can give type
multiple commands to identify at once.
您可以type
多个命令来一次识别。
type date top ls
-t选项 (The -t Option)
None of the options that type
will accept have names. So we can get our book of names out and christen them ourselves. If you think of the -t
option as standing for “terse,” you won’t be far wrong. It reduces the responses from type
to single word answers.
type
的所有选项都不会包含名称。 因此,我们可以拿出我们的地名簿,并自己为它们命名。 如果您认为-t
选项代表“简洁”,那么您肯定不会错。 它减少了从type
到单个单词答案的响应。
type -t date
type -t pwd
type -t lowdown
-a选项 (The -a Option)
Let’s call this one the “all” option. It lists all of the locations that the command is located in. Note that this option will not work if you also use the -p
option.
我们将此称为“全部”选项。 它列出了所有的命令位于位置。请注意,此选项将无法工作,如果你同时使用-p
选项。
For example, if you have an alias with the same name as the underlying command, you can get information on the alias and the command.
例如,如果您的别名与基础命令的名称相同,则可以获得有关别名和命令的信息。
type -a ls
-f选项 (The -f Option)
The -f
option forces type
to not search for user or system defined functions. Think of this option as “function search off.” Note that if the command is a function, type
will report that the command can’t be found.
-f
选项强制type
不搜索用户或系统定义的功能。 将此选项视为“关闭功能搜索”。 请注意,如果命令是函数,请type
以报告找不到该命令。
type -f top
type -f lowdown
-P选项 (The -P Option)
If you use the -P
option, type
will only search the directories in $PATH. So we can call this option “path.” Note that this option uses an uppercase “P.”
如果使用-P
选项,则type
将仅搜索$ PATH中的目录。 因此,我们可以将此选项称为“路径”。 请注意,此选项使用大写字母“ P”。
type -P date chmod adduser
-p选项 (The -p Option)
If you use the -p
option, type
will only respond if the command is a hard disk file. Note that this option uses a lowercase “p.”
如果使用-p
选项,则仅当命令是硬盘文件时, type
才会响应。 请注意,此选项使用小写的“ p”。
type -p mount
type -p ls
type -p -a ls
type
does not give any response for ls
because ls
an alias, and not a disk file.
type
对于ls
不会给出任何响应,因为ls
是别名,而不是磁盘文件。
But if we include the -a
option so that type
looks for all instances of the ls
command, it lists the underlying disk file that the ls
alias makes use of.
但是,如果我们包含-a
选项,以便该type
查找ls
命令的所有实例,则它将列出ls
别名使用的基础磁盘文件。
概要 (Summary)
That was nice and simple, but illuminating all the same.
那很好,很简单,但是却说明了一切。
We tend to think of anything we type at in a terminal window as a “command,” and we leave it at that. But actually, commands are implemented in a variety of ways in the Linux system. And type
lets you find out which one it is.
我们倾向于将在终端窗口中键入的任何内容视为“命令”,然后将其保留。 但是实际上,命令是在Linux系统中以多种方式实现的。 然后type
可以找出它是哪一个。
翻译自: https://www.howtogeek.com/426014/how-to-use-the-linux-type-command/
linux type命令