locate
檔案與目錄
用法
locate [name]查的是事先建好的索引而不是磁碟,所以秒出結果,但看不到上次 updatedb 之後新建的檔案。
常用選項
| 選項 | 含義 |
|---|---|
| -i | Ignore case |
| -l | Stop after N results |
| -c | Print only how many matched |
| -b | GNU mlocate: match the file name, not the whole path |
| -r | GNU: read the pattern as a regular expression |
| -e | GNU: skip entries that no longer exist on disk |
範例
locate -i nginx.confFinds the config anywhere on disk, instantly.
sudo updatedbRebuilds the index so new files can be found.
搬移、刪除和尋找。有些命令不會再問一次,所以順手加 -i 是在救自己。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. locate 是做什麼的?
查的是事先建好的索引而不是磁碟,所以秒出結果,但看不到上次 updatedb 之後新建的檔案。
Q. 怎麼寫?
locate [name] —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 6 個,完整列表在 man locate。這條命令屬於檔案與目錄。
相關命令
man 手冊: man locate