1个不稳定版本
0.1.0 | 2023年1月26日 |
---|
#6 in #ignore-case
86KB
2.5K SLoC
fgr
具有类似SQL查询语言的查找和grep实用工具。
示例
# Find all files with name equal to sample under the current directory:
fgr -e name=sample
# Find files with containing 's' and 777 permissions:
fgr /home /bin -e 'name=*s* and perm=777'
# Find files with name containing SAMPLE
fgr /home -e 'name="*SAMPLE*"'
# Find files with name containing SAMPLE ignore case
fgr /home -e 'name=i"*SAMPLE*"'
# Find files with name containing SAMPLE (regex)
fgr /home -e 'name=r".+SAMPLE.+"'
# Find files with name containing SAMPLE ignore case (regex)
fgr /home -e 'name=ri".+SAMPLE.+"'
# Find files under the /bin directory not owned by root:
fgr /bin -e 'user > 0'
# Find files under the /bin directory having suid bit (but not limited to):
fgr /bin -e 'perms>4000'
# Find recently accessed files (but not in future):
fgr /home -e 'atime > now - 1h and atime < now'
# Find stuff in files:
fgr /home -e 'type=text and contains=*stuff*'
# Other examples:
fgr /home /bin -e 'name=*s* and perm=777 or (name=*rs and contains=r".+user.is_birthday.*")'
fgr /home /bin -e 'name=*s* and perm=777 or (name=*rs and contains=*birth*)'
fgr /home /bin -e 'ext=so and mtime >= now - 1d'
fgr /home -e 'size>=1Mb and name != *.rs and type=vid'
# xargs & -print0 support
fgr /home -e 'perms=777' -p | xargs -0 -n1 | sort
功能
- 通过以下方式过滤文件
- 大小
- 深度
- 类型(文本、应用、归档、音频、书籍、文档、字体、图片、视频)
- atime、mtime
- 名称、扩展名
- 内容
- 用户、组、权限
- 超时IO操作(不会像
/sys/kernel/security/apparmor/revision
那样解析文件时挂起) - 正则表达式和Glob名称匹配
- 正则表达式和Glob内容匹配
- 嵌套表达式
- 可读的atime/mtime搜索模式
.ignore
支持,感谢 ignore crate
速度
默认情况下,它类似于 find
并访问所有目录。按名称搜索相当快
du -h /home
# 98G /home
# About 100G of .gradle, caches and all the whatnot
sudo sh -c 'echo 1 >/proc/sys/vm/drop_caches'
sudo sh -c 'echo 2 >/proc/sys/vm/drop_caches'
sudo sh -c 'echo 3 >/proc/sys/vm/drop_caches'
fgr /home -e 'name=*sample*' # 1.09s user 2.70s system 169% cpu 2.239 total
sudo sh -c 'echo 1 >/proc/sys/vm/drop_caches'
sudo sh -c 'echo 2 >/proc/sys/vm/drop_caches'
sudo sh -c 'echo 3 >/proc/sys/vm/drop_caches'
find /home -name '*sample*' # 0.71s user 2.09s system 12% cpu 22.156 total
待办事项
- 查询优先级评估
- 运行命令
- 排除模式 & 默认排除模式(处理
/proc/**/pagemap
场景) - 二进制/文本类型检测器
- 忽略大小写搜索
- 错误打印
- 文档
- AUR
依赖关系
~9–19MB
~252K SLoC