Launching Crab

USAGE

crab  [options]  [-db filename]   [path] [path]...  [sql | cmd]  [sql | cmd]...

filename is a crab database file to open or create.
If not specified, Crab will use the default database file

path is a path to scan, wildcards are supported on MacOS but not yet on Windows.
If no path is specified, Crab will open the database to query previous scan results. If you specify multiple paths they will all be scanned. If a path has spaces wrap it in double quotes

sql | cmd is a SQL query or Crab command, wrapped in double quotes
You can specify multiple queries, quote them separately

options:

-batch no Crab shell, exit after executing scan/SQL
-case new scans will be case sensitive
-color lightmode use colors suitable for command line window with a light background
-column set output mode to 'column'
-csv set output mode to 'csv'
-dict set output mode to 'dict'
-encoding 'name' set the encoding to use for file I/O
-init scriptfile read and process Crab script file
-line set output mode to 'line'
-list set output mode to 'list'
-maxdepth n scan only to depth n
-mount scan includes subdirectories that are mounted drives
-nocolor disable color output
-nullvalue 'string' set text string for NULL values
-refresh refresh scan results when opening database
-separator 'string' set output field separator (,)

Examples


Scan current directory recursively to default database, then open a Crab prompt

C:\> crab .


Open a Crab prompt on the default database to query previous scan results

C:\> crab


Scan whole disk and save scan data to specified file, exit after scan

C:\> crab -batch -db wholedisk20150828.crdb C:\


Start Crab with color scheme suitable for console with light background, and open specified scan data file

C:\> crab -color lightmode -db wholedisk20150828.crdb


Scan current directory tree to default database file, report biggest files, and exit

C:\> crab -batch . "select fullpath, bytes from files order by bytes desc limit 5"


Scan current directory and its contents, but no deeper, then open a Crab prompt

C:\> crab -maxdepth 1 .


Scan dir1 and dir2 in current directory recursively, then open a Crab prompt

C:\> crab dir1 dir2


-batch

Command line option to run Crab without a Crab prompt

Crab will exit after executing the scans or SQL commands you've specified, without giving a Crab prompt. Results are returned as lists, with a comma separator.


When to use the batch option

  • Use -batch to run a Crab scheduled job, perhaps to run a scheduled scan or a SQL analysis with a long run time.
  • Use -batch to return Crab query results to the command line, for example to pipe output from Crab to another program. N.B. Crab for Windows only supports pipes with ASCII characters.

Examples

Batch mode scan: Create or update the wholedisk.crdb Crab database by scanning the whole C drive

C:\> crab -batch -db C:\Users\johnsmith\wholedisk.crdb C:\


Instant Scan & SQL: Scan Dropbox and run a query, returning the results to the command line. By default batch mode returns comma separated results.

C:\> crab -batch C:\Users\johnsmith\Dropbox "select fullpath from files where extension = '.exe' "


C:\> crab -batch . "select fullpath, bytes from files order by bytes desc limit 5"

C:\> crab -batch . "select fullpath, bytes from files order by bytes desc limit 3"
C:\Users\johnsmith\myproject\gutenbergPreprocessing\alexandriaCatalogue.db,67335168
C:\Users\johnsmith\myproject\my off switch app store png images\my off switch app store ipad retina image2.idraw,48276511
C:\Users\johnsmith\myproject\.git\objects\pack\pack-7cbf3d2d26fc4b6e04b5affb8f874b1b669f543a.pack,45052625


Instant SQL: Run query against scan made earlier, and pipe the results to grep

C:\> crab -batch "select fullpath from files where name like '%apsw%' " | findstr '\.so'


Scan given path and run a file of crab commands and/or SQL queries called genhelp.crab


C:\> crab -batch C:\Users\johnsmith\Dropbox\PYTHONDROPBOX\sqlsys\ '%read genhelp.crab'



See %read command
To process a text file containing multiple Crab commands or SQL use the %read command

See -separator option
To change the separator used in list mode results as returned by -batch


-case

Command line option to set future scans as case sensitive.

Default behaviour is that scans are case insensitive, this option changes that.
Existing scan data is unaffected.


When to use the case option

When scanning a case sensitive file system.


Example

C:\> crab -case .


-color lightmode | default | off

Command line option to specify Crab color scheme at start up.


When to use the color option

On Windows the default color scheme is designed for a command line window with a dark background

  • Use -color lightmode  to get a color scheme suitable for use in a command line window with a light background
  • Use -color off  to get monochrome output.

Examples

C:\> crab -color lightmode


C:\> crab -color off



See %color command


-column

Command line option to set output to column mode.


Example


C:\> crab -column



See %mode command
%mode
changes output layout, column mode is one of the available options



-csv

Command line option to set output to csv mode.


Example


C:\> crab -csv



See %mode command
%mode
changes output layout, csv mode is one of the available options



-dict

Command line option to set output to dict mode.


Example


C:\> crab -dict



See %mode command
%mode
changes output layout, dict mode is one of the available options


-encoding  encodingType:errorHandler

Specifies how Crab should map byte sequences to characters when reading and writing files.

Affects reading from the fileslines table, and the %import and %autoimport commands. Writing is also affected for Crab's writeln and write functions, and the %output command.

Default value is
utf8:skipfile. Crab will correctly interpret UTF-8 and ASCII encoded characters, and when querying fileslines will silently skip to the next file when it meets a non-utf8 character. This prevents binary file contents from being echoed to screen.


Examples


Read and write with utf8 encoding, stop with error on invalid characters

C:\> crab -encoding utf8


Read and write with cp1252 encoding, replace invalid characters by placeholder symbol

C:\> crab -encoding cp1252:replace


Read and write with utf8 encoding, on invalid character skip to next file when querying fileslines

C:\> crab -encoding utf_8:skipfile


Read and write with ascii encoding, ignore any invalid characters

C:\> crab -encoding ascii:ignore


Read and write binary using blob objects, with buffer size of 80 bytes

C:\> crab -encoding binary:80


Read and write binary using blob objects, whole file as one data row

C:\> crab -encoding binary:-1



See %encoding command


-init scriptfile

Read and process Crab script file.


Examples


Scan current directory, process prefs.crab and open Crab command line

C:\> crab -init prefs.crab .


Open default.crdb scan data, run script transposeCsv.crab, and return results to command line

C:\> crab -batch -init C:\Users\johnsmith\Dropbox\crabScripts\transposeCsv.crab



See %read command


-line

Command line option to set output to line mode.


Example


C:\> crab -line



See %mode command
%mode
changes output layout, line mode is one of the available options


-list

Command line option to set output to list mode.


Example


C:\> crab -list



See %mode command
%mode
changes output layout, list mode is one of the available options


-maxdepth n

Command line option to specify how far down the directory tree Crab should scan.

A maxdepth of 0 means scan only the file or directory objects specified for scanning, the scan isn't continued down the directory tree. If a path to a directory is given, only one item - the directory itself - will be recorded, not its contents.

A maxdepth of 1 means recurse into directory contents one level down, and so on.

If you don't specify any maxdepth, the scan continues recursing down the directory tree until everything below the scan list has been scanned. Soft links aren't followed, and remote filesystems may or may not be scanned depending on the
-mount start up option.


When to use the -maxdepth option

  • You're only interested in the contents of a directory, not its subdirectories


Example

E.g. Count the lines in each file in the current directory


C:\> crab -maxdepth 1 -batch . "SELECT name, count(*) FROM fileslines GROUP BY name"


See -mount option


-mount

Command line option to tell Crab to scan mounted devices when descending directory trees.

By default scans only include files and directories that match devices on the original scan list: Any subdirectories that are the mount point for a different device, will be excluded. The -mount option changes this behaviour to recurse into mounted directories too.


Example

E.g. Scan the whole filesytem including mounted devices, and treat everything as case sensitive


C:\> crab -mount -case -batch -db alldisks.crdb C:\




-nocolor

Disable color output

Sets all output to monochrome. Same as -color off


When to use the -nocolor option

  • Your command line window is making a mess of the ANSI codes Crab outputs to switch colors
  • You dislike both the default and the darkmode color schemes


Example

E.g. Scan the current directory recursively, and open a Crab command line in monochrome


C:\> crab -nocolor .




-nullvalue 'string'

Set the string to be output in place of NULL values

Default is an empty string, ''


Example

E.g. Set the null replacement character to a single space


C:\> crab -nullvalue ' '


See %nullvalue command


-refresh

Refresh scan results when opening Crab

Triggers Crab to scan the orginal list of paths again, to repopulate the database. If the scan path was originally a set of wildcards the wildcards will not be re-evaluated, but the objects that matched will be scanned again.

Currently it's slower to scan with the -refresh option than to specify the paths again.


When to use the -refresh option

  • To update a Crab database in a batch job
  • To update a Crab database without having to retype the path


Examples


E.g. Refresh the scan data contained in wholedisk.crdb, and then exit


C:\> crab -batch -refresh -db wholedisk.crdb


E.g. Refresh the scan data contained in the default database and open a Crab command line on it

C:\> crab -refresh


-separator string

Change the separator used between fields for output in list mode, and importing text files with %import

Default list separator is ','



When to use the -separator option

  • to change the field separator when sending Crab output to your command line using the -batch option
  • to import a delimited file that uses a separator other than comma

Example
E.g. Report names and sizes of the biggest files, using pipe symbol as separator


C:\> crab -batch -separator '|' "SELECT name, bytes FROM files ORDER BY bytes DESC LIMIT 3"

C:\> crab -batch -separator '|' "SELECT name, bytes FROM files ORDER BY bytes DESC LIMIT 3"
alexandriaCatalogue.db|67335168
my off switch app store ipad retina image2.idraw|48276511
pack-7cbf3d2d26fc4b6e04b5affb8f874b1b669f543a.pack|45052625

See %mode and %separator commands
%mode
changes output layout, list mode is one of the available options

See Crab's -batch startup option

Crab's
-batch startup option defaults to list mode output

See %import


© 2017 Etia UK