cdb(1) | General Commands Manual | cdb(1) |
cdb - Constant DataBase manipulation tool
cdb -q [-m] [-n num] dbname key
cdb -d [-m] [dbname|-]
cdb -l [-m] [dbname|-]
cdb -s [dbname|-]
cdb -c [-m] [-t tmpname|-] [-p perms] [-weru0]
dbname [infile...]
cdb used to query, dump, list, analyze or create CDB (Constant DataBase) files. Format of cdb described in cdb(5) manpage. This manual page corresponds to version 0.78 of tinycdb package.
cdb -q finds given key in a given dbname cdb file, and writes associated value to standard output if found (and exits with zero), or exits with non-zero if not found. dbname must be seekable file, and stdin can not be used as input. By default, cdb will print all records found. Options recognized in query mode:
cdb -d dumps contents, and cdb -l lists keys of cdbfile (or standard input if not specified) to standard output, in format controlled by presence of -m option. See subsection "Formats" below. Output from cdb -d can be used as an input for cdb -c.
Cdb database created in two stages: temporary database is created, and after it is complete, it gets atomically renamed to permanent place. This avoids requirements for locking between readers and writers (or creaters). cdb -c will attempt to create cdb in file tmpname (or dbname with ".tmp" appended if no -t option given) and then rename it to dbname. It will read supplied infiles (or standard input if none specified). Options recognized in create mode:
Note that using any option that requires duplicate checking will slow creation process significantly, especially for large databases.
cdb -s will analyze dbfile and print summary to standard output. Statistics include: total number of rows in a file, minimum, average and maximum key and value lengths, hash tables (max 256) and entries used, number of hash collisions (that is, more than one key point to the same hash table entry), minimum, average and maximum hash table size (of non-empty tables), and number of keys that sits at 10 different distances from it's calculated hash table index — keys in distance 0 requires only one hash table lookup, 1 — two and so on; more keys at greater distance means slower database search.
By default, cdb expects (for create operation) or writes
(for dump/list) native cdb format data. Cdb native format is a sequence of
records in a form:
+klen,vlen:key->val\n
where "+", ",", ":", "-",
">" and "\n" (newline) are literal characters,
klen and vlen are length of key and value as decimal numbers,
and key and val are key and value themselves. Series of
records terminated by an empty line. This is the only format where key and
value may contain any character including newline, zero (\0) and so on.
When -l option requested (list keys mode), cdb will
produce slightly modified output in a form:
+klen:key\n
(note vlen and val are omitted, together with surrounding
delimiters).
If -m option is given, cdb will expect or produce one line for every record (newline is a record delimiter), and every line should contain optional whitespace, key, whitespace and value up to end of line. Lines started with hash character (#) and empty lines are ignored. This is the same format as mkmap(1) utility expects.
Here is a short summary of all options accepted by cdb utility:
The tinycdb package written by Michael Tokarev <mjt@corpit.ru>, based on ideas and shares file format with original cdb library by Dan Bernstein.
Public domain.
Jan 2009 |