欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

linux?type命令用法實戰(zhàn)教程

 更新時間:2023年05月11日 11:04:15   作者:yuxi_o  
type命令用來顯示指定命令的類型,它是Linux系統(tǒng)的一種自省機制,知道了是那種類型,我們就可以針對性的獲取幫助,這篇文章主要介紹了linux?type命令用法實戰(zhàn)教程,需要的朋友可以參考下

在腳本中type可用于檢查命令或函數(shù)是否存在,存在返回0,表示成功;不存在返回正值,表示不成功。

$ type foo >/dev/null 2>&1 || { echo >&2 "I require foo but it's not installed.  Aborting."; exit 1; }

用途說明

type命令用來顯示指定命令的類型。一個命令的類型可以是如下之一

  • alias 別名
  • keyword 關鍵字,Shell保留字
  • function 函數(shù),Shell函數(shù)
  • builtin 內建命令,Shell內建命令
  • file 文件,磁盤文件,外部命令
  • unfound 沒有找到

它是Linux系統(tǒng)的一種自省機制,知道了是那種類型,我們就可以針對性的獲取幫助。比如內建命令可以用help命令來獲取幫助,外部命令用man或者info來獲取幫助。

常用參數(shù)

type命令的基本使用方式就是直接跟上命令名字。

type -a可以顯示所有可能的類型,比如有些命令如pwd是shell內建命令,也可以是外部命令。

type -p只返回外部命令的信息,相當于which命令。

type -f只返回shell函數(shù)的信息。

type -t 只返回指定類型的信息。

使用示例

示例一 type自己是什么類型的命令

[root@new55 ~]#?type -a type?
type is a shell builtin
[root@new55 ~]#?help type?
type: type [-afptP] name [name ...]
??? For each NAME, indicate how it would be interpreted if used as a
??? command name.
??? If the -t option is used, `type' outputs a single word which is one of
??? `alias', `keyword', `function', `builtin', `file' or `', if NAME is an
??? alias, shell reserved word, shell function, shell builtin, disk file,
??? or unfound, respectively.
??? If the -p flag is used, `type' either returns the name of the disk
??? file that would be executed, or nothing if `type -t NAME' would not
??? return `file'.
??? If the -a flag is used, `type' displays all of the places that contain
??? an executable named `file'.? This includes aliases, builtins, and
??? functions, if and only if the -p flag is not also used.
??? The -f flag suppresses shell function lookup.
??? The -P flag forces a PATH search for each NAME, even if it is an alias,
??? builtin, or function, and returns the name of the disk file that would
??? be executed.
typeset: typeset [-afFirtx] [-p] name[=value] ...
??? Obsolete.? See `declare'.
[root@new55 ~]#

示例二 常見命令的類型

[root@new55 ~]#?type -a cd?
cd is a shell builtin
[root@new55 ~]#?type -a pwd?
pwd is a shell builtin
pwd is /bin/pwd
[root@new55 ~]#?type -a time?
time is a shell keyword
time is /usr/bin/time
[root@new55 ~]#?type -a date?
date is /bin/date
[root@new55 ~]#?type -a which?
which is aliased to `alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
which is /usr/bin/which
[root@new55 ~]#?type -a whereis?
whereis is /usr/bin/whereis
[root@new55 ~]#?type -a whatis?
whatis is /usr/bin/whatis
[root@new55 ~]#?type -a function?
function is a shell keyword
[root@new55 ~]#?type -a ls?
ls is aliased to `ls --color=tty'
ls is /bin/ls
[root@new55 ~]#?type -a ll?
ll is aliased to `ls -l --color=tty'
[root@new55 ~]#?type -a echo?
echo is a shell builtin
echo is /bin/echo
[root@new55 ~]#?type -a bulitin?
-bash: type: bulitin: not found
[root@new55 ~]#?type -a builtin?
builtin is a shell builtin
[root@new55 ~]#?type -a keyword?
-bash: type: keyword: not found
[root@new55 ~]#?type -a command?
command is a shell builtin
[root@new55 ~]#?type -a alias?
alias is a shell builtin
[root@new55 ~]#?type -a grep?
grep is /bin/grep

到此這篇關于linux type命令用法實戰(zhàn)教程的文章就介紹到這了,更多相關linux type命令內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • bash腳本中$符號的具體使用

    bash腳本中$符號的具體使用

    $符號主要用于訪問變量的值、參數(shù)擴展、算術運算以及命令替換等,本文主要介紹了bash腳本中$符號的具體使用,具有一定的參考價值,感興趣的可以了解一下
    2024-02-02
  • Nginx和PHP-FPM的啟動、重啟、停止腳本分享

    Nginx和PHP-FPM的啟動、重啟、停止腳本分享

    這篇文章主要介紹了Nginx和PHP-FPM的啟動、重啟、停止腳本分享,腳本中包含start、stop、reload、restart等常用的管理方法,并可以加入系統(tǒng)服務然后使用servicem命令管理,需要的朋友可以參考下
    2014-12-12
  • shell(bash)下“time” 命令的輸出詳解

    shell(bash)下“time” 命令的輸出詳解

    這篇文章主要給大家介紹了關于shell(bash) “time” 命令的輸出,文中給出了詳細的示例代碼,相信對大家的理解和學習具有一定的參考借鑒價值,有需要的朋友們下面來一起看看吧。
    2016-12-12
  • 局域網遠程開機軟件制作代碼分享

    局域網遠程開機軟件制作代碼分享

    局域網遠程開機軟件制作代碼分享,大家可以參考使用,要網卡支持,需要gtk+2.0 的庫支持UI
    2013-12-12
  • linux查看目錄的四種方法(ls只顯示目錄)

    linux查看目錄的四種方法(ls只顯示目錄)

    linux如何只列出目錄?下面介紹4種方法列出當前路徑下的目錄,大家參考使用吧
    2014-01-01
  • Linux Shell腳本系列教程(一):Shell入門

    Linux Shell腳本系列教程(一):Shell入門

    這篇文章主要介紹了Linux Shell腳本系列教程(一):Shell入門,本文講解了Shell簡介、Shell基本操作、如何打開Shell終端、Shell腳本的概念、如何運行Shell腳本、Shell腳本的注釋等基礎知識,需要的朋友可以參考下
    2015-06-06
  • linux shell腳本學習xargs命令使用詳解

    linux shell腳本學習xargs命令使用詳解

    xargs是一條Unix和類Unix操作系統(tǒng)的常用命令。它的作用是將參數(shù)列表轉換成小塊分段傳遞給其他命令,以避免參數(shù)列表過長的問題
    2013-12-12
  • linux shell 中判斷文件、目錄是否存在的方法

    linux shell 中判斷文件、目錄是否存在的方法

    這篇文章主要介紹了linux shell 中判斷文件、目錄是否存在的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-05-05
  • Linux查看端口、進程情況及kill進程的方法

    Linux查看端口、進程情況及kill進程的方法

    下面小編就為大家?guī)硪黄狶inux查看端口、進程情況及kill進程的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-05-05
  • Linux網絡設置詳情

    Linux網絡設置詳情

    這篇文章主要介紹了Linux網絡設置,需要的朋友可以參考下面文章內容
    2021-08-08

最新評論