linux type命令_如何使用Linux type命令

linux type命令

linux type命令

Terminal on a Linux laptop
Fatmawati Achmad Zaenuri/Shutterstock.com Fatmawati Achmad Zaenuri / Shutterstock.com

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 and elif. They are also called keywords.

    保留:shell保留的一个字,例如ifelif 。 它们也称为关键字。

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
type date in a terminal window

The date command is an executable disk file.

date命令是可执行的磁盘文件。

type ls
type ls in a terminal window

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
type lowdown in a terminal window

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命令是用户定义的功能,该功能是在用于研究本文的通勤者上设置的。 它提供了一些系统资源的快速快照。 它是whoamiwfreedf

type pwd
type pwd in a terminal window

The pwd command is a built-in command of the Bash shell.

pwd命令是Bash shell的内置命令。

type elif
type elif in a terminal window

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
type date top ls in a terminal window

-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
demonstration of type -t option in a terminal window

-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
demonstration of the type -a option in a terminal window

-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
demonstration of the type -f option in a terminal window

-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
type -P date chmod adduser in a terminal window

-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
demonstration of the type -p option in a terminal widow

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命令

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值