Giter Site home page Giter Site logo

fsq's Introduction

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
  • content (content can be queried, but cannot be added to the attribute list for printing)
  • modified (format: '01/02/2006' or '01/02/2006 15:04:05')

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')

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.