linux type命令的使用

Linux type命令的用法
一般情况下,type命令被用于判断另外一个命令是否是内置命令,但是它实际上有更多的用法。

  1.判断一个名字当前是否是alias、keyword、function、builtin、file或者什么都不是:

        type ls 的输出是 ls 是 `ls --color=auto' 的别名

        type if 的输出是 if 是 shell 关键字

        type type 的输出是 type 是 shell 内嵌

        type frydsh 的输出是 bash: type: frydsh: 未找到

  2.判断一个名字当前是否是alias、keyword、function、builtin、file或者什么都不是的另一种方法(适用于脚本编程):

        type -t ls 的输出是 alias

        type -t if 的输出是 keyword

        type -t type 的输出是 builtin

        type -t gedit 的输出是 file

        type -t frydsh 没有输出

  3.显示一个名字的所有可能:

        type -a kill 的输出是 kill 是 shell 内嵌 和 kill 是 /bin/kill

        type -at kill 的输出是 builtin 和 file

  4.查看一个命令的执行路径(如果它是外部命令的话):

        type -p gedit 的输出是 /usr/bin/gedit

        type -p kill 没有输出(因为kill是内置命令)

  5.强制搜索外部命令:

        type -P kill 的输出是 /bin/kill
posted @ 2021-01-19 11:02  helloweifa  阅读(228)  评论(0编辑  收藏  举报