語法:find <指定目錄> <指定條件> <指定動作>
| 參數 | 說明 |
|---|---|
| -name 模式 | 依檔名搜尋,支援萬用字元 * ? |
| -type x | 依檔案類型搜尋(f=一般檔、d=目錄、l=符號連結等) |
| -size n | 依大小搜尋(c=bytes、k=KB) |
| -mtime n | n 天前修改過的檔案 |
| -mmin n | n 分鐘前修改過的檔案 |
| -user name | 依擁有者搜尋 |
| -perm mode | 依權限搜尋 |
# 找出當前目錄下所有以 my 開頭的檔案
find . -name 'my*'
# 找出 10 分鐘內修改過的一般檔案
find . -type f -mmin -10
# 找出 /etc 下大小小於 2500 bytes 的檔案
find /etc -size -2500c -print
# 找出系統中名為 httpd.conf 的檔案
find / -name httpd.conf -print
透過預建資料庫(/var/lib/locatedb)搜尋,速度極快,但非即時。需先執行 updatedb 更新資料庫。
locate /etc/sh # 搜尋 /etc 下以 sh 開頭的檔案
locate -i ~/m # 忽略大小寫搜尋家目錄下以 m 開頭的檔案
whereis grep
# 參數:-b 二進制、-m 手冊、-s 原始碼
which grep
type cd # 顯示 shell 內建指令
type grep # 顯示外部指令及路徑
type -p grep # 相當於 which grep
updatedb)