終端下使用Linux不可避免要與諸多Linux命令打交道爆存,對(duì)于常用命令我們還大概都能記住幾種用法蛉顽,而對(duì)于冗長(zhǎng)命令、不常用命令以及這些命令的參數(shù)使用先较,要記清楚是不可能也是沒有必要的携冤。熟練使用Linux下的幫助命令,對(duì)我們掌握新命令的用法很有幫助闲勺。這里就簡(jiǎn)要總結(jié)一下Linux下的幾種幫助命令(help
曾棕、man
、info
)的使用菜循。
一睁蕾、內(nèi)建命令與外部命令
由于不同的命令(內(nèi)建命令vs外部命令)查詢幫助的方法不一樣,所以要查詢某個(gè)命令的幫助信息债朵,首先要確定這個(gè)命令是內(nèi)建命令還是外部命令。
內(nèi)建命令:Shell程序的一部分瀑凝,這些命令寫在bash源碼的buildins里面序芦,被Shell程序識(shí)別并運(yùn)行在Shell程序中,所以解析內(nèi)建命令Shell不需要?jiǎng)?chuàng)建子進(jìn)程粤咪,其執(zhí)行速度比外部命令快谚中;如:history,cd寥枝,exit等宪塔。
外部命令:Linux中的實(shí)用程序部分,在系統(tǒng)啟動(dòng)時(shí)不加載到內(nèi)存中囊拜,而是在需要時(shí)才會(huì)被調(diào)用到內(nèi)存中某筐。其執(zhí)行過程也是由Shell控制的,外部命令是在Bash之外安裝的冠跷,通常放在/bin南誊,/sbin身诺,/usr/bin,/usr/sbin等目錄中抄囚;如ls霉赡,vim等。
我們可以通過type
命令來確認(rèn)某個(gè)命令是內(nèi)建還是外部命令(第三種說明執(zhí)行的ls
命令是別名):
shiyanlou@16b6978c3fb4:~$ type cd
cd is a shell builtin
shiyanlou@16b6978c3fb4:~$ type vim
vim is /usr/bin/vim
shiyanlou@16b6978c3fb4:~$ type ls
ls is aliased to `ls --color=auto'
二幔托、常用幫助命令的使用
1.help
命令:
-
help
顯示Shell內(nèi)建命令的簡(jiǎn)要幫助信息:命令簡(jiǎn)要說明已經(jīng)一些參數(shù)的簡(jiǎn)要使用說明穴亏。
shiyanlou@16b6978c3fb4:~$ help ls
bash: help: no help topics match `ls'. Try `help help' or `man -k ls' or `in
fo ls'.
shiyanlou@16b6978c3fb4:~$ help vim
bash: help: no help topics match `vim'. Try `help help' or `man -k vim' or `
info vim'.
shiyanlou@16b6978c3fb4:~$ help exit
exit: exit [n]
Exit the shell.
Exits the shell with a status of N. If N is omitted, the exit status
is that of the last command executed.
- 非內(nèi)建命令如果需要help,則可以使用
--help
重挑。
shiyanlou:~/ $ ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short options too.
-a, --all do not ignore entries starting with .
-A, --almost-all do not list implied . and ..
--author with -l, print the author of each file
-b, --escape print C-style escapes for nongraphic characters
--block-size=SIZE scale sizes by SIZE before printing them. E.g.,
'--block-size=M' prints sizes in units of
1,048,576 bytes. See SIZE format below.
...
2.man
命令:
man
查詢命令幫助沒有內(nèi)建命令和外部命令之分嗓化,man
工具是顯示系統(tǒng)手冊(cè)頁中的內(nèi)容,是一本電子版的字典攒驰,這些內(nèi)容大多是對(duì)命令的解釋信息和一些相關(guān)的描述蟆湖。man
的每一章節(jié)顯示的信息可以參考前文《基本概念及操作》。打開手冊(cè)之后我們可以通過d
玻粪、e
按鍵來翻頁隅津。
3.info
命令:
info
來自于自由軟件基金會(huì)的GNU項(xiàng)目,是GNU的超文本幫助系統(tǒng)劲室,能夠完整顯示出GNU信息伦仍。