命令的查看 分內部命令 和外部命令
查看外部命令 可用 man command–help info
查看內部命令 可用 help command
man 幫助是 使用最頻繁的 命令查看 而 man 又有很多選項 如下
man – format and display the on-line manual pages
SYNOPSIS
man [-acdDfFhkKtwW] [–path] [-m system] [-p string] [-C config_file]
[-M pathlist] [-P pager] [-B browser] [-H htmlpager] [-S section_list]
[section] name …
DESCRIPTION
man formats and displays the on-line manual pages. If you specify sec-
tion, man only looks in that section of the manual. name is normally
the name of the manual page, which is typically the name of a command,
function, or file. However, if name contains a slash (/) then man
interprets it as a file specification, so that you can do man ./foo.5
or even man /cd/foo/bar.1.gz.
See below for a description of where man looks for the manual page
files.
MANUAL SECTIONS
The standard sections of the manual include:
:
由于 選項過多 而我們平時 用到的 并不是全部 所以 在此簡要 說明 幾個重要選項如下
-K 搜索所有字符串 頁面
-A 列出所有幫助
-C config_file
Specify the configuration file to use; the default is @man_con-
fig_file@. (See man.conf(5).)
-M path
Specify the list of directories to search for man pages. Sepa-
rate the directories with colons. An empty list is the same as
not specifying -M at all. See SEARCH PATH FOR MANUAL PAGES.
-P pager
Specify which pager to use. This option overrides the MANPAGER
environment variable, which in turn overrides the PAGER vari-
able. By default, man uses @pager@.
-B Specify which browser to use on HTML files. This option over-
rides the BROWSER environment variable. By default, man uses
@browser@,
-H Specify a command that renders HTML files as text. This option
overrides the HTMLPAGER environment variable. By default, man
uses @htmlpager@,
在搜索出的 man命令頁面解釋中 我們可以使用一些快捷鍵例如
man命令的操作方法:使用less命令實現 Space, ^V, ^f, ^F: 向文件尾翻屏
b, ^B: 向文件首部翻屏
d, ^D: 向文件尾部翻半屏
u, ^U: 向文件首部翻半屏
RETURN, ^N, e, ^E or j or ^J: 向文件尾部翻一行
y or ^Y or ^P or k or ^K:向文件首部翻一行
q: 退出 #:跳轉至第#行
1G: 回到文件首部
G:翻至文件尾部
也可以
/KEYWORD: 以KEYWORD指定的字符串為關鍵字,從當前位置向文件 尾部搜索;
不區分字符大小寫; n: 下一個 N:上一個 ?
?KEYWORD: 以KEYWORD指定的字符串為關鍵字,從當前位置向文件 首部搜索;
不區分字符大小寫; n: 跟搜索命令同方向,下一個 N:跟搜索命令反方向,上一個
友情提示 有時 info比man更詳細 當然 視情況而定
man常用于命令參考 ,GNU工具info適合通用文檔參考。 ?
沒有參數,列出所有的頁面 ?
info 頁面的結構就像一個網站 ? 每一頁分為“節點” ? 鏈接節點之前 * ?info [ 命令 ]
下面 簡要 介紹一下 history 的 用法 以及 命令歷史行的 調用
命令行擴展:$( ) 或 “ ? 把一個命令的輸出打印給另一個命令的參數 $ echo "This system's name is $(hostname) " This system's name is server1.example.com $echo "i am `whoami` " i am root ? 括號擴展:{ } ? 打印重復字符串的簡化形式 $ echo file{1,3,5} file1 file3 file5 $ rm -f file{1,3,5}
保存你輸入的命令歷史??梢杂盟鼇碇貜蛨绦忻?? 登錄shell時,會讀取命令歷史文件中記錄下的命令 ~/.bash_history ? 登錄進shell后新執行的命令只會記錄在緩存中;這些命 令會用戶退出時“追加”至命令歷史文件中
重復前一個命令,有4種方法:
重復前一個命令使用上方向鍵,并回車執行。
按 !! 并回車執行。 輸入 !-1 并回車執行。
按 Ctrl+p 并回車執行。 ?!字符串:重復前一個以“字符串”開頭的命令 ?
!num:按照history命令輸出中的序號重復對應命令 ?!?字符串:重復前一個包含abc的命令 ?
!-n :重復n個命令之前的那個命令
使用up(向上)和down(向下)鍵來上下瀏覽從前輸入 的命令 ?
鍵入ctrl-r來在命令歷史中搜索命令 ? (reverse-i-search)`’: ? 要重新調用前一個命令中最后一個參數: ?
!$ 表示 ? Esc, .(點擊Esc鍵后松開,然后點擊 . 鍵) ? Alt+ .(按住Alt鍵的同時點擊 . 鍵)
以及調用歷史參數
如下
#cmd !^ : 利用上一個命令的第一個參數做cmd的參數 ?
#cmd !$ : 利用上一個命令的最后一個參數做cmd的參數 ?
#cmd !* : 利用上一個命令的全部參數做cmd的參數 ?
#cmd !:n : 利用上一個命令的第n個參數做cmd的參數
!string:^ 從命令歷史中搜索以 string 開頭的命令,并獲取 它的第一個參數 ?
!string:$ 從命令歷史中搜索以 string 開頭的命令,并獲取它 的最后一個參數 ?
!string:n 從命令歷史中搜索以 string 開頭的命令,并獲取 它的第n個參數 ?
!string:* 從命令歷史中搜索以 string 開頭的命令,并獲取 它的所有參數
history 的 一些 命令選項
history [-c] [-d offset] [n] ?history -anrw [filename] ?history -ps arg [arg…]
-c: 清空命令歷史
-d: 刪除歷史中指定的命令; #: 顯示最近的#條歷史
-a: 追加本次會話新執行的命令歷史列表至歷史文件
-n: 讀歷史文件中未讀過的行到歷史列表
-r: 讀歷史文件附加到歷史列表
-w: 保存歷史列表到指定的歷史文件
-p: 展開歷史參數成多個行,但不存在歷史列表中
-s: 展開歷史參數成一行,附加在歷史列表后
和命令歷史相關的環境變量
HISTSIZE:命令歷史記錄的條數; ?
HISTFILE:指定歷史文件,默認為~/.bash_history; ?
HISTFILESIZE:命令歷史文件記錄歷史的條數; ?
HISTTIMEFORMAT=“%F %T“ 顯示時間 ?
HISTIGNORE=“str1:str2:… “ 忽略string1,string2歷史 ? 控制命令歷史的記錄方式: 環境變量:
HISTCONTROL ignoredups:忽略重復的命令;連續且相同方為“重復” ignorespace:忽略所有以空白開頭的命令 ignoreboth:ignoredups, ignorespace erasedups:刪除重復命令 ? export 變量名="值“ ? 存放在 /etc/profile 或 ~/.bash_profile
友情附加 一些關于 bash 的 快捷鍵
Ctrl+l 清屏,相當于clear命令 ?
Ctrl+c 取消命令的執行 ?
Ctrl-a 會移動到命令行的最前面 ?
Ctrl-e 會移動到命令行的最后面 ?
Ctrl-u 會刪除到行首 ?
Ctrl-k 會刪除到行尾 ?
arrow ctrl-b ctrl-f會向左或向右移動一個字符 ?
Esc-b 左移一個單詞 ?
Esc-f 右移一個單詞
原創文章,作者:a1215276209,如若轉載,請注明出處:http://www.www58058.com/33232