高性能 Find
如果 JuiceFS 文件系统中已经存有海量文件,需要按照特定条件搜索,那么 Linux 自带的 find 可能性能会比较差,从 v5.3.7 开始,可以使用 juicefs find 命令作为 find 的高性能替代,通常会比 find 快 1~2 个数量级。凡是 find 支持的用法,我们都期望在 juicefs find 中予以支持。
功能概述
juicefs find 命令用于在 JuiceFS 挂载点中按条件递归查找文件或目录,并支持执行动作(如打印、删除、执行外部命令)。
该实现采用两阶段过滤:
- 服务端过滤(元数据侧):基于表达式 AST 在元数据树上做快速筛选,减少回传数据量。
- 客户端过滤与动作执行(挂载侧):对服务端返回条目做最终表达式求值并执行动作。默认动作为
-print。
命令格式
juicefs find [PATH ...] [EXPRESSION]
简单示例:
juicefs find /mnt/jfs -name "*.log"
juicefs find /mnt/jfs -type f -size +10M -print
juicefs find /mnt/jfs -name "*.tmp" -a -delete
juicefs find /mnt/jfs -type f -exec ls -l {} \;
高级用法示范:
# 查找大文件
juicefs find /mnt/jfs -type f -size +1G
# 查找最近 1 天内修改的日志
juicefs find /mnt/jfs -name "*.log" -mtime -1
# 忽略大小写查找路径
juicefs find /mnt/jfs -ipath "*backup*"
# 组合条件
juicefs find /mnt/jfs -type f -a \( -name "*.go" -o -name "*.md" \)
# 执行动作
juicefs find /mnt/jfs -type f -name "*.tmp" -delete
juicefs find /mnt/jfs -type f -name "*.log" -exec gzip {} \;
选项与语法
遍历选项:
-p, --threads N并发参数(当前实现中建议优先使用 -p)-maxdepth N最 大遍历深度-mindepth N最小匹配深度。
逻辑运算:
- 与:
-a, -and(也支持隐式与) - 或:
-o, -or - 非:
!, -not - 分组:
(...)
表达式遵循常见优先级:
- 括号
- 非
- 与
- 或
支持的谓词:
- 名称与路径:
-name, -iname, -path, -ipath - 正则:
-regex, -iregex - 类型:
-type (f|d|l) - 大小:
-size [+|-]N[KMGT] - 时间:
-mtime, -atime, -ctime, -mmin, -amin, -cmin, -newer, -anewer, -cnewer, -newerXY - 其他:
-empty, -links, -inum, -perm, -user, -group, -nouser, -nogroup
支持的动作:
-print未显式提供动作时,这是默认动作-print0-exec CMD {} \;目前不支持-exec ... +形式-delete


