高性能 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 {} \;