fsq
1.10.0
fsq
(“文件系统查询”——发音为“fisk”)实用程序是一种使用类似 SQL 的表达式语言对文件系统进行即席查询的工具。这对于查找符合特定条件的文件非常有用,而无需编写一次性脚本来执行此操作。
下载适合您平台的二进制文件并将其添加到您的命令行路径。
fsq
采用单个参数:表达式。该表达式由以下部分组成:
<attribute list> [not] in <locations> where <conditions>
要递归查找“/data”目录下以字符“hello”开头且大于 5 mb 的所有文件,可以使用以下查询:
fsq "name in '/data' where name startswith 'hello' and size > 5m"
如果省略位置(在上述情况下为“/data”), fsq
将默认为当前目录:
fsq "name where name startswith 'hello' and size > 5m"
也可以指定多个位置:
fsq "name in '/opt', '/media' where size > 5m"
位置也可能被排除。在以下示例中,将搜索当前目录下除.git
之外的所有位置以查找包含字符串“implements MyInterface”的文件:
fsq "path not in '.git' where content contains 'implements MyInterface'"
属性列表指定fsq
将哪些属性打印到标准输出。在上面的例子中,这只是文件名('name')。以下示例将打印文件的路径和大小(以字节为单位):
fsq "path,size in '/opt' where size > 5m"
name
path
size
fsize
(可以在属性列表中使用,但不能查询)content
(内容可以查询,但不能添加到属性列表中进行打印)modified
(格式:'MM/DD/YYYY' 或 'MM/DD/YYYY hh:mm:ss')sha1
sha256
md5
stats
(可以在属性列表中使用,但不能查询)<
<=
>
>=
=
!=
startswith
endswith
isdir
(该运算符不带任何参数)isfile
(该运算符不带任何参数)contains
ignorecase
(后面必须跟“=”、“!=”、“startswith”、“endswith”或“contains”)matches
(正则表达式匹配)括号以及逻辑运算符or 、 and和not可用于对条件进行分组。例如:
fsq "name in '.' where name startswith 'hello' or (isdir and not name startswith 'world')"
可以将以下大小限定符附加到整数值以指示非默认单位。当在表达式中指定文件大小时,这些特别有用。如果整数上没有附加大小限定符,则fsq
会比较该值(以字节为单位)。
例如,要查找所有大于 10 KB 且小于 1 MB 的文件:
fsq "path where size > 10k and size < 1m"
构建fsq
需要go
编译器。如果安装了make
,则可以使用以下命令安装fsq
:
make install
否则,需要在fsq
目录中运行以下命令:
go get golang.org/x/tools/cmd/goyacc
go install golang.org/x/tools/cmd/goyacc
goyacc parser.y
go install