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 supported on MacOS, but not yet on Windows.
If no path is specified, Crab will open the database to query previous scan results

sql | cmd is a SQL query or Crab command, wrapped in quotes

options:

-batch no Crab shell, exit after executing scan/SQL
-case new scans will be case sensitive
-color darkmode use colors suitable for dark 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

$ crab .


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

$ crab


Scan whole disk from root and save scan data to specified file, exit after scan. Mounted drives won't be scanned.

$ crab -batch -db wholedisk20150828.crdb /


Start crab with color scheme suitable for terminal with dark background, and open specified scan data file

$ crab -color darkmode -db wholedisk20150828.crdb


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

$ 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

$ crab -maxdepth 1 .


Scan both this directory and that directory recursively to default database, then open a Crab prompt

$ crab ~/this ~/that


Scan all text files in the current directory to default database, then open a Crab prompt

$ crab *.txt


-batch

Command line option to run Crab without a Crab command line.

Crab will exit after executing the scans or SQL commands you've specified. 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 OS shell, for example to pipe output from Crab to another program.

Examples

Batch mode refresh: Update existing default Crab database by re-scanning the original scanpath

$ crab -batch '%refresh'


Batch mode scan: Create or update the wholedisk.crbd Crab database by scanning the whole filesystem from root

$ crab -batch -db ~/wholedisk.crbd /


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

$ crab -batch ~/Dropbox "SELECT fullpath FROM files WHERE extension = '.exe' "


$ crab -batch . "select fullpath, bytes from files order by bytes desc limit 5"

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


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

$ crab -batch "SELECT fullpath from files where name like '%apsw%' " | grep '\.so'


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


$ crab -batch ~/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, such as a time machine backup.


Example

$ crab -case .


-color darkmode | default | off

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


When to use the color option

The default color scheme is designed to be readable with a light colored background

  • Use color darkmode to get a color scheme suitable for use in a terminal window with a dark background
  • Use color off to get monochrome output, if your terminal does not successfully interpret ANSI color codes.

Examples

$ crab -color darkmode


$ crab -color off



See %color command


-column

Command line option to set output to column mode.


Example


$ 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


$ 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


$ 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

$ crab -encoding utf8


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

$ crab -encoding cp1252:replace


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

$ crab -encoding utf_8:skipfile


Read and write with ascii encoding, ignore any invalid characters

$ crab -encoding ascii:ignore


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

$ crab -encoding binary:80


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

$ 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

$ crab -init prefs.crab .


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

$ crab -batch -init ~/Dropbox/crabScripts/transposeCsv.crab



See %read command


-line

Command line option to set output to line mode.


Example


$ 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


$ 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


$ 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


$ crab -mount -case -batch -db alldisks.crdb /




-nocolor

Disable color output

Sets all output to monochrome. Same as -color off


When to use the -nocolor option

  • Your terminal is making a mess of the ANSI codes Crab outputs to switch colors
  • You passionately 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


$ 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


$ 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.


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


$ 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

$ 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 shell 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


$ crab -batch -separator '|' "SELECT name, bytes FROM files ORDER BY bytes DESC LIMIT 3"

$ 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