7个版本
0.8.6 | 2024年5月3日 |
---|---|
0.8.5 | 2023年12月30日 |
0.8.4 | 2023年6月16日 |
0.8.2 | 2023年3月4日 |
0.3.2 |
|
#67 in 文件系统
每月225次下载
355KB
8K SLoC
fselect
使用类似SQL的查询查找文件
为什么使用fselect?
虽然它并不完全取代传统的 find
和 ls
,但 fselect 具有以下优点
- 类似SQL(不是真正的SQL,但非常宽松!)的语法,易于人类理解
- 复杂查询
- 聚合、统计、日期和其他功能
- 在存档中搜索
- 支持
.gitignore
、.hgignore
和.dockerignore
(实验性) - 根据图像的宽度和高度进行搜索,EXIF元数据
- 根据MP3信息进行搜索
- 根据扩展文件属性进行搜索
- 根据文件哈希进行搜索
- 根据MIME类型进行搜索
- 常用文件类型的快捷键
- 交互式模式
- 各种输出格式(CSV、JSON等)
更多功能正在开发中!
安装
从源代码的最新版本
- 安装 Rust with Cargo 及其依赖项以构建二进制文件
- 运行
cargo install fselect
Arch Linux
NixOS
fselect
in nixpkgs
,感谢 @filalex77
其他Linux
Windows 64位
在GitHub下载中提供静态预编译的二进制文件:fselect-x86_64-win.zip
通过winget安装Windows
- 安装 winget
- 运行
winget install -e --id fselect.fselect
通过 Chocolatey 安装 Windows
- 安装 Chocolatey
- 运行
choco install fselect
通过 Scoop 安装 Windows
- 安装 Scoop
- 运行
scoop install fselect
通过 Homebrew 安装 Mac
- 安装 brew
- 运行
brew install fselect
通过 MacPorts 安装 Mac
- 安装 MacPorts
- 使用方法
sudo port selfupdate sudo port install fselect
交互模式
fselect [ARGS] COLUMN[, COLUMN...] [from ROOT[, ROOT...]] [where EXPR] [group by COLUMNS] [order by COLUMNS] [limit N] [into FORMAT]
文档
fselect -i
更详细描述。首先查看示例。
查找临时或配置文件(完整路径和大小)
Windows 用户可能省略引号
fselect size, path from /home/user where name = '*.cfg' or name = '*.tmp'
或将所有参数放入引号中,如下所示
fselect size, path from C:\Users\user where name = *.cfg or name = *.tmp
查找具有任何内容(大小 > 0)的文件(仅文件名)
fselect "name from /home/user/tmp where size > 0"
指定文件大小,获取绝对路径,并将其添加到结果中
fselect name from /home/user/tmp where size gt 0
更复杂的查询
cd /home/user
fselect size, abspath from ./tmp where size gt 2g
fselect fsize, abspath from ./tmp where size = 5m
fselect hsize, abspath from ./tmp where size lt 8k
fselect name, size from ./tmp where size between 5mb and 6mb
聚合函数(如果您愿意,可以使用大括号,并且甚至可以与常规括号结合使用)
fselect "name from /tmp where (name = *.tmp and size = 0) or (name = *.cfg and size > 1000000)"
格式化函数
fselect "MIN(size), MAX{size}, AVG(size), SUM{size}, COUNT(*) from /home/user/Downloads"
获取最旧文件的年份
fselect "LOWER(name), UPPER(name), LENGTH(name), YEAR(modified) from /home/user/Downloads"
如果需要引用有空格的文件,请使用单引号
fselect "MIN(YEAR(modified)) from /home/user"
Rust 风格的正则表达式(请参阅文档)受支持
fselect "path from '/home/user/Misc stuff' where name != 'Some file'"
否定正则表达式
fselect name from /home/user where path =~ '.*Rust.*'
简单的 globs 会自动展开,并与 =
和 !=
运算符一起工作
fselect "name from . where path !=~ '^\./config'"
经典 LIKE
fselect name from /home/user where path = '*Rust*'
禁用正则表达式的精确匹配运算符以进行搜索
fselect "path from /home/user where name like '%report-2018-__-__???'"
按日期查找文件
fselect "path from /home/user where name === 'some_*_weird_*_name'"
更具体地匹配下午3点到4点之间创建的所有文件
fselect path from /home/user where created = 2017-05-01
fselect path from /home/user where modified = today
fselect path from /home/user where accessed = yesterday
fselect "path from /home/user where modified = 'apr 1'"
fselect "path from /home/user where modified = 'last fri'"
更具体
fselect path from /home/user where created = '2017-05-01 15'
日期和时间间隔是可能的(查找自5月1日以来更新的所有内容)
fselect path from /home/user where created = '2017-05-01 15:10'
fselect path from /home/user where created = '2017-05-01 15:10:30'
默认是当前目录
fselect path from /home/user where modified gte 2017-05-01
在多个位置内搜索
fselect path, size where name = '*.jpg'
指定最小和/或最大深度(depth
是 maxdepth
的同义词)
fselect path from /home/user/oldstuff, /home/user/newstuff where name = '*.jpg'
可选地跟踪符号链接
fselect path from /home/user/oldstuff depth 5 where name = '*.jpg'
fselect path from /home/user/oldstuff mindepth 2 maxdepth 5, /home/user/newstuff depth 10 where name = '*.jpg'
在存档内搜索(目前仅支持 zip-存档)
fselect path, size from /home/user symlinks where name = '*.jpg'
或组合使用
fselect path, size from /home/user archives where name = '*.jpg'
启用 .gitignore
或 .hgignore
支持
fselect size, path from /home/user depth 5 archives symlinks where name = '*.jpg' limit 100
按图像尺寸搜索
fselect size, path from /home/user/projects gitignore where name = '*.cpp'
fselect size, path from /home/user/projects hgignore where name = '*.py'
查找方形图像
fselect CONCAT(width, 'x', height), path from /home/user/photos where width gte 2000 or height gte 2000
查找具有已知名称部分但未知扩展名的图像
fselect path from /home/user/Photos where width = height
查找老式说唱 MP3 文件
fselect path from /home/user/projects where name = "*RDS*" and width gte 1
到常用文件扩展名的快捷方式
fselect duration, path from /home/user/music where genre = Rap and bitrate = 320 and mp3_year lt 2000
使用布尔列的更简单方法
fselect path from /home/user where is_archive = true
fselect path, mime from /home/user where is_audio = 1
fselect path, mime from /home/user where is_book != false
查找具有危险权限的文件
fselect path from /home/user where is_doc
fselect path from /home/user where is_image
fselect path from /home/user where is_video
简单的 glob 样式表达式或甚至可以在文件模式上使用正则表达式
fselect mode, path from /home/user where other_write or other_exec
fselect mode, path from /home/user where other_all
按所有者的 uid 或 gid 查找文件
fselect mode, path from /home/user where mode = '*rwx'
fselect mode, path from /home/user where mode =~ '.*rwx$'
或按所有者或组的名称查找
fselect uid, gid, path from /home/user where uid != 1000 or gid != 1000
查找特殊文件
fselect user, group, path from /home/user where user = mike or group = mike
查找具有 xattrs 的文件,检查是否存在特定的 xattr 或获取其值
fselect name from /usr/bin where suid
fselect path from /tmp where is_pipe
fselect path from /tmp where is_socket
将任意文本作为列包含
fselect "path, has_xattrs, has_xattr(user.test), xattr(user.test) from /home/user"
分组结果
fselect "name, ' has size of ', size, ' bytes'"
排序结果
fselect "ext, count(*) from /tmp group by ext"
最后限制结果
fselect path from /tmp order by size desc, name
fselect modified, fsize, path from ~ order by 1 desc, 3
格式化输出
fselect name from /home/user/samples limit 5
许可
fselect size, path from /home/user limit 5 into json
fselect size, path from /home/user limit 5 into csv
fselect size, path from /home/user limit 5 into html
MIT/Apache-2.0
由 JetBrains IDEA 开源许可支持
依赖项
~22–34MB
~511K SLoC
~511K SLoC