Bash編程011——獲取幫助信息

Bash編程010——獲取幫助信息

遇到問題使用搜索引擎前,我們可以先試試這些方法。

當(dāng)面對命令不知道怎么用,或不記得命令的拼寫及參數(shù)時,我們需要求助于系統(tǒng)的幫助文檔; linux系統(tǒng)內(nèi)置的幫助文檔很詳細(xì),通常能解決我們的問題,我們需要掌握如何正確的去使用它們,本節(jié)介紹一些使用幫助文檔的方法。

10.1 whatis

使用whatis可以查看命令的簡要說明,每個手冊頁中都有一個概述。whatis 搜索手冊頁名稱并顯示任何與 名稱 匹配的手冊頁描述。使用格式:whatis keyword

# 示例
whatis whatis
# 輸出:whatis (1)           - 顯示在線手冊頁說明
whatis help
# 輸出

10.2 man

man - 在線參考手冊的接口

man是系統(tǒng)的手冊分頁程序。指定給man的頁選項通常是程序、工具或函數(shù)名。程序?qū)@示每一個找到的相關(guān) 手冊頁。如果指定了 章節(jié),man 將只在手冊的指定章節(jié)搜索。默認(rèn)將按預(yù)定的順序查找所有可用的章節(jié) (默認(rèn)是“1 n l 8 3 2 3posix 3pm 3perl 5 4 9 6 7”,除非被 /etc/manpath.config 中的 SECTION 指令覆蓋),并只顯示找到的第一個 頁,即使多個章節(jié)中都有這個頁面。

下面顯示了手冊的 章節(jié) 號及其包含的手冊頁類型。

1 可執(zhí)行程序或 shell 命令

2 系統(tǒng)調(diào)用(內(nèi)核提供的函數(shù))
3 庫調(diào)用(程序庫中的函數(shù))
4 特殊文件(通常位于 /dev)
5 文件格式和規(guī)范,如 /etc/passwd
6 游戲
7 雜項(包括宏包和規(guī)范,如 man(7),groff(7))
8 系統(tǒng)管理命令(通常只針對 root 用戶)
9 內(nèi)核例程 (非標(biāo)準(zhǔn))

詳細(xì)使用方法可以采用man man查看。

10.3 which和whereis

which可以查看可執(zhí)行文件的路徑。which -a name可以查看所有匹配的可執(zhí)行文件路徑。

# 示例
which which
# 結(jié)果:/usr/bin/which

which man
# 結(jié)果:/usr/bin/man

which -a which
# 結(jié)果
/usr/bin/which
/bin/which

whereis定位命令的二進(jìn)制文件、源文件以及手冊頁的路徑。

# 示例
whereis whereis
# 結(jié)果:whereis: /usr/bin/whereis /usr/share/man/man1/whereis.1.gz

# 示例
whereis man
# 結(jié)果:man: /usr/bin/man /usr/local/man /usr/share/man /usr/share/man/man7/man.7.gz /usr/share/man/man1/man.1.gz

10.4 help

help——顯示builtins的相關(guān)信息。

獲取所有的builtins可以通過compgen -b獲得

# 示例
help for
# 輸出如下:
for: for 名稱 [in 詞語 ... ] ; do 命令; done
    為列表中的每個成員執(zhí)行命令。
    
    `for' 循環(huán)為列表中的每個成員執(zhí)行一系列的命令。如果沒有
    `in WORDS ...;'則假定使用 `in "$@"'。對于 WORDS 中的每
     個元素,NAME 被設(shè)定為該元素,并且執(zhí)行 COMMANDS 命令。
    
    退出狀態(tài):
    返回最后執(zhí)行的命令的狀態(tài)。

10.5 使用--help或者-h

適用于外部命令,格式:command --help 或者command -h

# 示例
ls --help
# 輸出如下:
用法:ls [選項]... [文件]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

必選參數(shù)對長短選項同時適用。
  -a, --all         不隱藏任何以. 開始的項目
  -A, --almost-all      列出除. 及.. 以外的任何項目
      --author          與-l 同時使用時列出每個文件的作者
  -b, --escape          以八進(jìn)制溢出序列表示不可打印的字符
      --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
  -B, --ignore-backups       do not list implied entries ending with ~
  -c                         with -lt: sort by, and show, ctime (time of last
                               modification of file status information);
                               with -l: show ctime and sort by name;
                               otherwise: sort by ctime, newest first
  -C                         list entries by columns
      --color[=WHEN]         colorize the output; WHEN can be 'always' (default
                               if omitted), 'auto', or 'never'; more info below
  -d, --directory            list directories themselves, not their contents
  -D, --dired                generate output designed for Emacs' dired mode
  -f                         do not sort, enable -aU, disable -ls --color
  -F, --classify             append indicator (one of */=>@|) to entries
      --file-type            likewise, except do not append '*'
      --format=WORD          across -x, commas -m, horizontal -x, long -l,
                               single-column -1, verbose -l, vertical -C
      --full-time            like -l --time-style=full-iso
  -g                類似-l,但不列出所有者
      --group-directories-first
                             group directories before files;
                               can be augmented with a --sort option, but any
                               use of --sort=none (-U) disables grouping
  -G, --no-group             in a long listing, don't print group names
  -h, --human-readable       with -l and/or -s, print human readable sizes
                               (e.g., 1K 234M 2G)
      --si                   likewise, but use powers of 1000 not 1024
  -H, --dereference-command-line
                             follow symbolic links listed on the command line
      --dereference-command-line-symlink-to-dir
                             follow each command line symbolic link
                               that points to a directory
      --hide=PATTERN         do not list implied entries matching shell PATTERN
                               (overridden by -a or -A)
      --indicator-style=WORD  append indicator with style WORD to entry names:
                               none (default), slash (-p),
                               file-type (--file-type), classify (-F)
  -i, --inode                print the index number of each file
  -I, --ignore=PATTERN       do not list implied entries matching shell PATTERN
  -k, --kibibytes            default to 1024-byte blocks for disk usage
  -l                使用較長格式列出信息
  -L, --dereference     當(dāng)顯示符號鏈接的文件信息時,顯示符號鏈接所指示
                的對象而并非符號鏈接本身的信息
  -m                所有項目以逗號分隔,并填滿整行行寬
  -n, --numeric-uid-gid     類似 -l,但列出UID 及GID 號
  -N, --literal         輸出未經(jīng)處理的項目名稱 (如不特別處理控制字符)
  -o                類似 -l,但不列出有關(guān)組的信息
  -p,  --indicator-style=slash  對目錄加上表示符號"/"
  -q, --hide-control-chars   print ? instead of nongraphic characters
      --show-control-chars   show nongraphic characters as-is (the default,
                               unless program is 'ls' and output is a terminal)
  -Q, --quote-name           enclose entry names in double quotes
      --quoting-style=WORD   use quoting style WORD for entry names:
                               literal, locale, shell, shell-always,
                               shell-escape, shell-escape-always, c, escape
  -r, --reverse         逆序排列
  -R, --recursive       遞歸顯示子目錄
  -s, --size            以塊數(shù)形式顯示每個文件分配的尺寸
  -S                         sort by file size, largest first
      --sort=WORD            sort by WORD instead of name: none (-U), size (-S),
                               time (-t), version (-v), extension (-X)
      --time=WORD            with -l, show time as WORD instead of default
                               modification time: atime or access or use (-u);
                               ctime or status (-c); also use specified time
                               as sort key if --sort=time (newest first)
      --time-style=STYLE     with -l, show times using style STYLE:
                               full-iso, long-iso, iso, locale, or +FORMAT;
                               FORMAT is interpreted like in 'date'; if FORMAT
                               is FORMAT1<newline>FORMAT2, then FORMAT1 applies
                               to non-recent files and FORMAT2 to recent files;
                               if STYLE is prefixed with 'posix-', STYLE
                               takes effect only outside the POSIX locale
  -t                         sort by modification time, newest first
  -T, --tabsize=COLS         assume tab stops at each COLS instead of 8
  -u                         with -lt: sort by, and show, access time;
                               with -l: show access time and sort by name;
                               otherwise: sort by access time, newest first
  -U                         do not sort; list entries in directory order
  -v                         natural sort of (version) numbers within text
  -w, --width=COLS           set output width to COLS.  0 means no limit
  -x                         list entries by lines instead of by columns
  -X                         sort alphabetically by entry extension
  -Z, --context              print any security context of each file
  -1                         list one file per line.  Avoid '\n' with -q or -b
      --help        顯示此幫助信息并退出
      --version     顯示版本信息并退出

The SIZE argument is an integer and optional unit (example: 10K is 10*1024).
Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).

使用色彩來區(qū)分文件類型的功能已被禁用,默認(rèn)設(shè)置和 --color=never 同時禁用了它。
使用 --color=auto 選項,ls 只在標(biāo)準(zhǔn)輸出被連至終端時才生成顏色代碼。
LS_COLORS 環(huán)境變量可改變此設(shè)置,可使用 dircolors 命令來設(shè)置。

退出狀態(tài):
 0  正常
 1  一般問題 (例如:無法訪問子文件夾)
 2  嚴(yán)重問題 (例如:無法使用命令行參數(shù))

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
請向<http://translationproject.org/team/zh_CN.html> 報告ls 的翻譯錯誤
Full documentation at: <http://www.gnu.org/software/coreutils/ls>
or available locally via: info '(coreutils) ls invocation'
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 學(xué)習(xí)LInux的過程是痛苦的,經(jīng)常會遇到各種各樣的困難。那獲取到幫助就顯得尤為重要?;驇椭饕幸韵聨讉€途徑。 w...
    Aubin閱讀 389評論 0 0
  • 官網(wǎng) 中文版本 好的網(wǎng)站 Content-type: text/htmlBASH Section: User ...
    不排版閱讀 4,727評論 0 5
  • 1、使用命令 1.1、命令是什么: A、是一個可執(zhí)行程序,就像我們所看到的位于目錄/usr/bin 中的文件一樣...
    夏日不歸閱讀 541評論 0 1
  • 第一章 引言 shell 是和鍵盤打交道的,但你也可以在終端仿真器里使用鼠標(biāo)。X 窗口系統(tǒng) (使 GUI 工作的底...
    cccshuang閱讀 391評論 0 0
  • 猜猜這是哪里?
    sinbadgod閱讀 288評論 0 0

友情鏈接更多精彩內(nèi)容