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