whereis 專門定位「程式相關檔案」:二進制執行檔、原始碼、man 手冊頁。它不掃描磁碟,而是查詢預建資料庫,速度極快,是管理員尋找指令位置的首選工具。
whereis [-bmsu] [-BMS 目錄] -f 檔案名
-b 只找二進制檔
-m 只找手冊頁
-s 只找原始碼
-u 找不尋常檔案 (無上述三類)
-B 指定二進制搜尋路徑
-M 指定手冊頁搜尋路徑
-S 指定原始碼搜尋路徑
-f 結束目錄參數,開始檔案名 (配合 -B/-M/-S)
/var/lib/mlocate/mlocate.db (mlocate) 或 /var/lib/locate/locate.db (舊 locate)/etc/cron.daily/mlocate 每日執行 updatedb# 1. 完整查詢 (三類皆找)
whereis nginx
# nginx: /usr/sbin/nginx /usr/lib/nginx/modules /etc/nginx /usr/share/man/man8/nginx.8.gz
# 2. 只找二進制
whereis -b nginx
# nginx: /usr/sbin/nginx /usr/lib/nginx/modules
# 3. 只找手冊頁
whereis -m nginx
# nginx: /usr/share/man/man8/nginx.8.gz
# 4. 只找原始碼 (通常套件不含原始碼,除非安裝 src.rpm/deb-src)
whereis -s nginx
# nginx:
# 5. 指定搜尋路徑
whereis -B /opt/nginx/sbin -f nginx
| 特性 | whereis | locate | find |
|---|---|---|---|
| 搜尋對象 | 程式三件套 (bin/man/src) | 所有檔案 (檔名) | 所有檔案 (屬性/內容/類型) |
| 速度 | 極快 (資料庫) | 極快 (資料庫) | 慢 (掃描磁碟) |
| 即時性 | 非即時 | 非即時 | 即時 |
| 條件豐富度 | 低 | 低 (支援正則) | 極高 (型別/大小/時間/權限/深度/執行動作) |
| 典型用途 | 確認指令安裝位置、man 頁位置 | 模糊記得檔名找路徑 | 精確條件搜尋、批次處理 |
updatedb (需 root)/etc/updatedb.conf 設定 PRUNEPATHSwhereis -b nginx | cut -d: -f2 | xargs ls -lwhereis -b ls → /usr/bin/ls → rpm -qf /usr/bin/ls (核對套件)知道程式名,要找執行檔/man page 位置 → whereis
模糊記得檔名關鍵字,要找路徑 → locate
需按大小/時間/型別/權限/內容搜尋 → find
需即時結果 → find (或 fd/ripgrep)
whereis 專注、極速、零負擔,是「確認指令安裝狀態」的黃金工具。善用 -b/-m/-s 精準鎖定所需檔案類別。