https://github.com/upcrob/fsq
A tool for querying the file system with a SQL-like language.
https://github.com/upcrob/fsq
cli command-line filesystem go language regex search terminal tool
Last synced: 5 months ago
JSON representation
A tool for querying the file system with a SQL-like language.
- Host: GitHub
- URL: https://github.com/upcrob/fsq
- Owner: upcrob
- License: bsd-3-clause
- Created: 2016-01-17T23:51:46.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2025-01-25T16:28:52.000Z (over 1 year ago)
- Last Synced: 2025-01-25T17:26:54.277Z (over 1 year ago)
- Topics: cli, command-line, filesystem, go, language, regex, search, terminal, tool
- Language: Go
- Size: 104 KB
- Stars: 73
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fsq
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](https://github.com/upcrob/fsq/releases/latest) the binary for your platform and add it to your command line path.
## Usage
### Query Structure
`fsq` takes a single argument: the expression. This expression is composed of the following parts:
[not] in where
### 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"
Locations may also be excluded. In the following example, all locations under the current directory except for `.git` will be searched for files containing the string, "implements MyInterface":
fsq "path not in '.git' where content contains 'implements MyInterface'"
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')
* `sha1`
* `sha256`
* `md5`
* `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