Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

help 命令怎麼用:查 Shell 內建指令的語法與說明

在 Linux 上遇到不熟悉的指令,多數人直覺反應是 man。但有一類指令是 shell 自己內建的(例如 cd、pwd、echo、alias),它們沒有獨立的 man 頁面,這時就該請出 help。

本文整理自人民郵電出版社《Linux 命令應用大詞典》,該書收錄 729 個命令、1935 個實例,遇到卡住的參數直接翻查即可,很適合當案頭工具書。

基本語法

help [選項] [命令]

兩個最實用的選項

選項用途
-d只顯示該命令簡短的主題描述
-s只顯示該命令簡短的語法格式

實作演練:以 pwd 為例

查看完整說明

[root@rhel ~]# help pwd
pwd: pwd [-LP]
Print the name of the current working directory.

Options:
 -L print the value of $PWD if it names the current working directory
 -P print the physical directory, without any symbolic links

By default, `pwd' behaves as if `-L' were specified.

Exit Status:
Returns 0 unless an invalid option is given or the current directory
cannot be read.

只看語法摘要

[root@rhel ~]# help -s pwd
pwd: pwd [-LP]

只看一句話描述

[root@rhel ~]# help -d pwd
pwd - Print the name of the current working directory.

help、man、info 怎麼分工

三者定位不同:help 針對 shell 內建指令,輸出精簡;man 是萬用說明手冊,涵蓋絕大多數外部程式與設定檔;info 則提供章節式的完整文件,可跳轉閱讀。搭配使用,例如 help cd 加上 man bash,幾乎能解決所有語法疑問。

小技巧:若想一次瀏覽某個內建指令的所有說明,可以不加任何選項直接執行 help 指令名;若想列出全部內建指令,直接輸入 help 即可。

本文出自「airfish2000」部落格,請務必保留此出處 https://airfish2000.blog.51cto.com/10829608/1871365

Copyright © Linux教程網 All Rights Reserved