Linux運維基礎之whatis命令詳解

Linux運維基礎之whatis命令詳解

它與 “man” 命令非常相似,但該命令只列印給定命令的一行說明。它可以方便地瞭解命令的用途,而不需要額外的細節。

whatis 命令的一般語法:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
whatis [OPTIONS...] [COMMAND]
whatis [OPTIONS...] [COMMAND]
whatis [OPTIONS...] [COMMAND]

1. 顯示(多個)命令的資訊

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
whatis [command] [command]
whatis [command] [command]
whatis [command] [command]

whatis 命令可用於提供多個 Linux 命令的簡要手冊說明。為此,只需指定幾條命令即可。

示例:

下面是執行 whatis ls mkdir 時可能看到的輸出示例:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
ls (1) - list directory contents
mkdir (1) - make directories
ls (1) - list directory contents mkdir (1) - make directories
ls (1)               - list directory contents
mkdir (1)            - make directories

在本例中:

  • ls (1)ls 命令, (1) 指的是 ls 所在的手冊章節。說明 “列出目錄內容” 是對 ls 命令作用的簡要概括。
  •  mkdir (1)mkdir 命令,(1) 指的是 mkdir 所在的手冊章節。關於 “建立目錄” 的說明簡要概括了 mkdir 命令的作用。

2. 顯示除錯資訊

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
whatis -d [command]
whatis -d [command]
whatis -d [command]

要在終端中顯示 Linux 命令的除錯資訊,請使用帶有 -d 選項的 whatis 命令。

3. 通過正規表示式搜尋

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
whatis -r [command]
whatis -r [command]
whatis -r [command]

-r 選項按關鍵字名稱搜尋命令。如果其中任何名稱與頁面名稱的任何部分匹配,就會輸出該匹配結果。

示例:

執行 whatis -r cp 時,將返回與正規表示式 cp 匹配的所有命令的列表。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
cp (1) - copy files and directories
cpio (1) - copy files to and from archives
scp (1) - secure copy (remote file copy program)
gcp (1) - advanced file copier
cp (1) - copy files and directories cpio (1) - copy files to and from archives scp (1) - secure copy (remote file copy program) gcp (1) - advanced file copier
cp (1)               - copy files and directories
cpio (1)             - copy files to and from archives
scp (1)              - secure copy (remote file copy program)
gcp (1)              - advanced file copier

4. 按規則搜尋命令

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
whatis -w [command* or *command]
whatis -w [command* or *command]
whatis -w [command* or *command]

使用 -w 選項可以使用萬用字元搜尋 Linux 命令。指定一個模式,搜尋與該條件規則匹配的命令。

示例:

whatis -w cd* 將顯示 man 頁中所有以 “cd” 開頭的命令的描述。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
cd (1) - change the shell working directory
cdrecord (1) - record audio or data Compact Discs or Digital Versatile Discs from a master
cdrdao (1) - writes audio CD-Rs in disc-at-once (DAO) mode
cdparanoia (1) - an audio CD reading utility which includes extra data verification features
cd (1) - change the shell working directory cdrecord (1) - record audio or data Compact Discs or Digital Versatile Discs from a master cdrdao (1) - writes audio CD-Rs in disc-at-once (DAO) mode cdparanoia (1) - an audio CD reading utility which includes extra data verification features
cd (1)               - change the shell working directory
cdrecord (1)         - record audio or data Compact Discs or Digital Versatile Discs from a master
cdrdao (1)           - writes audio CD-Rs in disc-at-once (DAO) mode
cdparanoia (1)       - an audio CD reading utility which includes extra data verification features

5. 使用其他作業系統的手冊頁

1 whatis -m [manual_directory] [command]

通過 -m 選項可以訪問包含要搜尋的手冊頁面的目錄路徑。

示例:

如果從 /opt/myprogram/man 目錄搜尋 cat 命令,會得到以下結果:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
cat (1) - concatenate files and print on the standard output
cat (1) - concatenate files and print on the standard output
cat (1) - concatenate files and print on the standard output

更多 Linux 命令

下面羅列了最常見的一些 Linux 命令,您可以根據自己的需要查閱對應命令的詳細解析:

目錄操作 rmdir · cd · pwd · exa · ls
檔案操作 cat · cp · dd · less · touch · ln · rename · more · head
檔案系統操作 chown · mkfs · locate
網路 ping · curl · wget · iptables · mtr
搜尋和文字處理 find · grep · sed · whatis · ripgrep · fd · tldr
系統資訊和管理 env · history · top · who · htop · glances · lsof
使用者和會話管理 screen · su · sudo · open

此外,我們還整理 Linux 命令列大全,以幫助大家全面深入地學習 Linux。

評論留言