4 种命令方式:
locate
whereis
which
find
locate 命令跟一个系统的内部数据库有关, 这个数据库每天 (或每周) 更新一次, 会返回关键字在文件系统里面所有的存在路径, 可以想象这是一个重量级查询返回的信息是最多的.
locate keyword如果搜查的是最新的数据, 可能出现内部据库还为将其索引的情况, 可以尝试手动更新
updatedb在 linux 可执行文件被称为二进制文件, 而 whereis 命令就是专门找二进制文件的
whereis binary限制为环境变量 PATH 中存在的二进制文件.
可以直接执行的命令 e.g., nginx -s reload 可以直接使用, 表示路径已经存在环境变量中, 可以直接用 which 来搜索, 作为 whereis 的子集, 应该优先使用这个命令
which binary可以指定路径并使用各种参数的强力查找命令
find directory options expressione.g., 想找一个不知道路径名叫 test.txt 的文件.
find / -type f -name test.txt
type 类型:
- f 文件
- b block special device file
- c character special device file
- d 目录
- l 符号链接文件
name 查找名称: 完全匹配
在命令前面加上 time 可以计算命令所耗时间
time find /home -type f -name test.txt
支持通配符 wildcards
* 匹配多个字符 *at 将匹配:cat、hat、what and bat? 匹配单个字符 ?at 将匹配 cat、hat、bat (不匹配 what)[] 匹配出现在方括号内的字符 [c,b] 将匹配 cat and bat选项 options 可以进行组合
find ~ \( -type f -not -perm 0600 \) -or \( -type d -not perm 0700 \)