Skip to content
A tool for querying the file system with a SQL-like language.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
testdata Rewrite of file content searching. Feb 25, 2017
.gitignore Ignore binaries. Dec 28, 2017
.travis.yml
LICENSE
Makefile
README.md Documentation update. May 24, 2018
RELEASENOTES.md Released version 1.7.3. Oct 19, 2018
bintray.json Released version 1.7.3. Oct 19, 2018
evaluator.go Implemented 'matches' keyword. Nov 7, 2017
files.go
files_test.go
integration_test.go Initialize maxRoutines in tests. Oct 19, 2018
lexer.go Implemented 'matches' keyword. Nov 7, 2017
main.go Released version 1.7.3. Oct 19, 2018
optimize.go
parser.y Implemented 'matches' keyword. Nov 7, 2017
parsetree.go
validate.go Implemented 'matches' keyword. Nov 7, 2017

README.md

fsq

Build Status

The fsq ('file system query' - pronounced, 'fisk') utility is a tool for doing ad-hoc queries against a file system using a SQL-like expression language. This is useful for finding files that match certain criteria without writing a one-off script to do so.

Installation

Download the binary for your platform and add it to your command line path.

Download

Usage

Query Structure

fsq takes a single argument: the expression. This expression is composed of the following parts:

<attribute list> in <locations> where <conditions>

Example Queries

To recursively find all files under the '/data' directory that start with the characters 'hello' and are larger than 5 mb, the following query could be used:

fsq "name in '/data' where name startswith 'hello' and size > 5m"

If the location (in the above case, '/data') is omitted, fsq will default to the current directory:

fsq "name where name startswith 'hello' and size > 5m"

Multiple locations can be specified as well:

fsq "name in '/opt', '/media' where size > 5m"

The attribute list specifies which attributes are printed to standard out by fsq. In the above case, this is just the filename ('name'). The following example will print both the path to the file and the size (in bytes):

fsq "path,size in '/opt' where size > 5m"

Supported Attributes

  • name
  • path
  • size
  • fsize (can be used in the attribute list, but cannot be queried)
  • content (content can be queried, but cannot be added to the attribute list for printing)
  • modified (format: 'MM/DD/YYYY' or 'MM/DD/YYYY hh:mm:ss')
  • stats (can be used in the attribute list, but cannot be queried)

Supported Conditional Operators

  • <
  • <=
  • >
  • >=
  • =
  • !=
  • startswith
  • endswith
  • isdir (this operator does not take any arguments)
  • isfile (this operator does not take any arguments)
  • contains
  • ignorecase (must be followed by '=', '!=', 'startswith', 'endswith', or 'contains')
  • matches (regular expression matching)

Logic Operators

Parentheses as well as the logical operators or, and, and not can be used to group conditions. For example:

fsq "name in '.' where name startswith 'hello' or (isdir and not name startswith 'world')"

Size Qualifiers

The following size qualifiers can be appended to integer values to indicate non-default units. These are especially useful when specifying file sizes in expressions. If no size qualifier is appended to an integer, fsq compares the value in bytes.

  • k - Kilobytes
  • m - Megabytes
  • g - Gigabytes

For example, to find all files greater than 10 kilobytes and less than 1 megabyte:

fsq "path where size > 10k and size < 1m"

Building

The go compiler is required to build fsq. If you have make installed, fsq can be installed with:

make install

Otherwise, the following commands will need to be run while in the fsq directory:

go get golang.org/x/tools/cmd/goyacc
go install golang.org/x/tools/cmd/goyacc
goyacc parser.y
go install
You can’t perform that action at this time.