linux帮助命令和用法,Linux命令帮助及history命令的使用
1.Linux命令幫助的獲取詳解
在Linux中獲取命令幫助時,內部命令和外部命令的獲取方式是有區(qū)別的:
即
(1)內部命令:#help COMMAND
? ? ? ? ? ? ?#man bash
(2)外部命令:<1> # COMMAND --help
# COMMAND -h
<2> ?使用手冊(manual)
# man COMMAND
<3> 信息頁
# info COMMAND
<4> ?程序自身的幫助文檔等
README
INSTALL
ChangeLog
內部命令本身一開機就會隨bash加載到內存中
而外部命令只會運行后才會加載到內存中可以用hash命令看到
當前shell為bash如果想要查看bash幫助信息,可以通過man bash 來查看,同時我們知道bash提供了許多內部命令如cd ,l等,如果用man bash 來查看幫助信息實際看到的為bash的幫助信息,因此內部命令不通過man來查看。
[root@localhost ~]# echo $PATH
/usr/lib64/qt3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
hash表的作用:大大提高命令的調用速率。
hash的參數:
[root@redhat ~]# hash //輸入hash或hash -l 可以查看hash表的內容,我剛開機所以為空
hash: hash table empty
[root@redhat ~]# hash -l
hash: hash table empty
當我執(zhí)行過2條命令后再看:
[root@redhat ~]# hash //hash表會記錄下執(zhí)行該命令的次數,以及命令的絕對路徑
hits command
1 /bin/cat
1 /bin/ls
[root@redhat ~]# hash -l //加參數-l既可以看到hash表命令的路徑,也可以看到它的名字,說不定會有別名哦
builtin hash -p /bin/cat cat
builtin hash -p /bin/ls ls
[root@redhat ~]# hash -p /bin/ls bb //添加hash表,可以看到我把ls命令重新寫了一遍,改名為bb
當前shell為bash如果想要查看bash幫助信息,可以通過man bash 來查看,同時我們知道bash提供了許多內部命令如cd ,l等,如果用man bash 來查看幫助信息實際看到的為bash的幫助信息,因此內部命令不通過man來查看。
[root@localhost ~]# echo $PATH
/usr/lib64/qt3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
hash表的作用:大大提高命令的調用速率。
hash的參數:
[root@redhat ~]# hash //輸入hash或hash -l 可以查看hash表的內容,我剛開機所以為空
hash: hash table empty
[root@redhat ~]# hash -l
hash: hash table empty
當我執(zhí)行過2條命令后再看:
[root@redhat ~]# hash //hash表會記錄下執(zhí)行該命令的次數,以及命令的絕對路徑
hits command
1 /bin/cat
1 /bin/ls
[root@redhat ~]# hash -l //加參數-l既可以看到hash表命令的路徑,也可以看到它的名字,說不定會有別名哦
builtin hash -p /bin/cat cat
builtin hash -p /bin/ls ls
[root@redhat ~]# hash -p /bin/ls bb //添加hash表,可以看到我把ls命令重新寫了一遍,改名為bb
[root@redhat ~]# bb //當我執(zhí)行bb時就是執(zhí)行l(wèi)s
anaconda-ks.cfg ? ? ? ?icmp_echo_ignore_aly~ ?pub.key
dead.letter ? ? ? ?icmp_echo_ignore_alz~ ?rpmbuild
icmp_echo_ignore_all~ ?install.log ? ? ? RPM-GPG-KEY-useradd
icmp_echo_ignore_alw~ ?install.log.syslog ? ? RPM-GPG-KEY-westos
icmp_echo_ignore_alx~ ?passwd
[root@redhat ~]# hash -t ls //-t參數可以查看hash表中命令的路徑,要是hash表中沒有怎么辦?
/bin/ls
[root@redhat ~]# hash -t df //我沒使用過df,執(zhí)行hash,就會提示找不到該命令
-bash: hash: df: not found
[root@redhat ~]# hash -r //清楚hash表,清楚的是全部的
[root@redhat ~]# hash -l
hash: hash table empty
[root@redhat ~]# hash -l
builtin hash -p /bin/cat cat
builtin hash -p /bin/ls ls
[root@redhat ~]# hash -d cat //清楚其中的某一條
[root@redhat ~]# hash -l
builtin hash -p /bin/ls ls
2.history命令
〈一〉history是管理命令歷史,每次執(zhí)行的命令都會紡織在內存緩存中,直到退出當前終端后保存在歷史文件中。
root@linux ~]# history [n]
[root@linux ~]# history [-c]
[root@linux ~]# history [-raw] histfiles
參數:n?:數字,意思是‘要列出最近的?n?筆命令列表’的意思!-c?:將目前的?shell?中的所有?history?內容全部消除-a?:將目前新增的?history?指令新增入?histfiles?中,若沒有加?histfiles?,則預設寫入?~/.bash_history
-r?:將?histfiles?的內容讀到目前這個?shell?的?history?記憶中;-w?:將目前的?history?記憶內容寫入?histfiles?中!范例:范例一:列出目前記憶體內的所有?history?記憶[root@linux ~]# history
#?前面省略1017??man bash
1018??ll
1019??history
1020??history
#?列出的資訊當中,共分兩欄,第一欄為該指令在這個?shell?當中的代碼,#?另一個則是指令本身的內容,至于會出幾筆指令記錄,則與?HISTSIZE?有關!
范例二:列出目前最近的?3?筆資料[root@linux ~]# history 3
1019??history
1020??history
1021??history 3范例三:立刻將目前的資料寫入?histfile?當中[root@linux ~]# history -w
#?在預設的情況下,會將歷史紀錄寫入?~/.bash_history?當中![root@linux ~]# echo $HISTSIZE
1000在正常的情況下,當我們以?bash?登入?Linux?主機之后,系統(tǒng)會主動的由家目錄的?~/.bash_history?讀取以前曾經下過的指令,那么?~/.bash_history?會記錄幾筆資料呢?這就與你?bash?的?HISTSIZE?這個變數設定值有關了!在預設的?FC4?底下,是會記錄?1000?筆資料的! 那么假設我這次登入主機后,共下達過?100?次指令,‘等我登出時, 系統(tǒng)就會將?101~1100?這總共?1000?筆歷史命令更新到?~/.bash_history?當中。’?也就是說,歷史命令在我登出時,會將最近的?HISTSIZE?筆記錄到我的紀錄檔當中當然,也可以用?history -w?強制立刻寫入的!那為何用‘更新’兩個字呢? 因為?~/.bash_history?記錄的筆數永遠都是?HISTSIZE?那么多,舊的訊息會被主動的拿掉!僅保留最新的
〈二〉簡單常用的調用歷史中的命令。
[root@linux ~]# !number
[root@linux ~]# !command
[root@linux ~]# !!參數:number?:執(zhí)行第幾筆指令的意思;command?:由最近的指令向前搜尋‘指令串開頭為?command’的那個指令,并執(zhí)行;!!:就是執(zhí)行上一個指令(相當于按↑按鍵后,按?Enter)范例:[root@linux ~]# history
66??manrm
67?alias
68??manhistory
69?history
[root@linux ~]# !66??<==執(zhí)行第66?筆指令[root@linux ~]# !!??<==執(zhí)行上一個指令,本例中亦即?!66
[root@linux ~]# !al?<==執(zhí)行最近以?al?為開頭的指令(上頭列出的第?67?個)
總結
以上是生活随笔為你收集整理的linux帮助命令和用法,Linux命令帮助及history命令的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python实现访问者模式
- 下一篇: 就业阶段-java语言进价_day05