1.\" $NetBSD: db.1,v 1.25 2009/01/28 09:11:16 wiz Exp $ 2.\" 3.\" Copyright (c) 2002-2009 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by Luke Mewburn of Wasabi Systems. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" POSSIBILITY OF SUCH DAMAGE. 29.\" 30.Dd January 28, 2009 31.Dt DB 1 32.Os 33. 34.Sh NAME 35.Nm db 36.Nd 37manipulate 38.Xr db 3 Ns 's 39.Xr btree 3 40and 41.Xr hash 3 42databases 43. 44.Sh SYNOPSIS 45.Nm 46.Op Fl DKiNqV 47.Op Fl E Ar endian 48.Op Fl f Ar infile 49.Op Fl O Ar outsep 50.Op Fl S Ar visitem 51.Op Fl T Ar visspec 52.Op Fl U Ar unvisitem 53.Op Fl X Ar extravis 54.Ar type 55.Ar dbfile 56.Op Ar key Op Ar \&.\&.\&. 57. 58.Nm 59.Fl d 60.Op Fl iNq 61.Op Fl E Ar endian 62.Op Fl f Ar infile 63.Op Fl T Ar visspec 64.Op Fl U Ar unvisitem 65.Ar type 66.Ar dbfile 67.Op Ar key Op Ar \&.\&.\&. 68. 69.Nm 70.Fl w 71.Op Fl CDiNqR 72.Op Fl E Ar endian 73.Op Fl F Ar insep 74.Op Fl f Ar infile 75.Op Fl m Ar mode 76.Op Fl P Ar pagesize 77.Op Fl T Ar visspec 78.Op Fl U Ar unvisitem 79.Ar type 80.Ar dbfile 81.Op Ar key Ar value Op Ar \&.\&.\&. 82. 83.Sh DESCRIPTION 84.Nm 85allows manipulation of 86.Xr btree 3 87and 88.Xr hash 3 89.Pq Xr db 3 90databases. 91.Pp 92.Nm 93has three modes of operation to perform upon 94.Ar dbfile : 95.Bl -tag -width "delete" -offset indent 96.It read 97Displays the given 98.Ar key Ns s , 99and keys described in 100.Ar infile . 101If no keys and no 102.Ar infile 103is specified, the entire database is displayed. 104This is the default mode of operation. 105.It delete 106Enabled with 107.Fl d . 108Deletes the given 109.Ar key Ns s , 110and keys described in 111.Ar infile . 112.It write 113Enabled with 114.Fl w . 115Writes the given 116.Ar key Ns s 117and 118.Ar value Ns s , 119and keys and values described in 120.Ar infile 121(in the latter case, entries are separated by 122.Ar insep ) . 123.El 124.Pp 125There are two mandatory arguments: 126.Ar type 127is the database type; either 128.Sq Sy btree 129or 130.Sq Sy hash , 131and 132.Ar dbfile 133is the database file to manipulate. 134.Pp 135Options valid for all modes are: 136.Bl -tag -width Fl -offset indent 137. 138.It Fl E Ar endian 139Set the endianness of the database. 140.Ar endian 141may be one of: 142.Bl -tag -width 1n -offset indent -compact 143.It Sy B 144Big endian 145.It Sy H 146Host endian 147.It Sy L 148Little endian 149.El 150Defaults to 151.Sq H 152(host endian). 153. 154.It Fl f Ar infile 155Contains a list of keys 156(for read and delete), or 157.Ar insep 158separated keys and values (for write) 159to be used as arguments to the given mode. 160If 161.Ar infile 162is 163.Sq Sy - , 164.Dv stdin 165is used. 166. 167.It Fl i 168Keys are converted to lower case before manipulation. 169. 170.It Fl N 171Do not include the NUL byte at the end of the key or value. 172. 173.It Fl q 174Quiet operation. 175In read mode, missing keys are not considered to be an error. 176In delete 177.Pq Fl d 178and write 179.Pq Fl w 180modes, 181the result of various operations is suppressed. 182. 183.It Fl T Ar visspec 184Control how the items specified by the 185.Fl S 186option are encoded 187and 188.Fl U 189option are decoded. 190The 191.Ar visspec 192option-argument is a string specifying 193.Xr strsvisx 3 194flags. 195The string consists of one or more characters: 196.Bl -tag -width 2n -offset indent -compact 197.It Sy b 198.Dv VIS_NOSLASH 199.It Sy c 200.Dv VIS_CSTYLE . 201Overrides 202.Sy h 203and 204.Sy o . 205.It Sy h 206.Dv VIS_HTTPSTYLE . 207Overrides 208.Sy c 209and 210.Sy o . 211.It Sy o 212.Dv VIS_OCTAL . 213Overrides 214.Sy c 215and 216.Sy h . 217.It Sy s 218.Dv VIS_SAFE 219.It Sy t 220.Dv VIS_TAB 221.It Sy w 222.Dv VIS_WHITE 223.El 224.Pp 225.Fl U 226only supports 227.Fl T 228.Sy h . 229.Pp 230See 231.Xr vis 1 Ns 's 232corresponding options for the meaning of these characters, 233and 234.Xr strsvisx 3 235for more detail on the flags. 236. 237.It Fl U Ar unvisitem 238Specify items to 239.Xr strunvisx 3 240decode. 241The 242.Ar unvisitem 243option-argument is a character specifying if the key 244.Pq Ar k , 245the value 246.Pq Ar v 247or both 248.Pq Ar b 249should be decoded. 250. 251.El 252. 253.Pp 254Read mode specific options are: 255. 256.Bl -tag -width Fl -offset indent 257. 258.It Fl D 259Display duplicate entries in 260.Sy btree 261databases. 262. 263.It Fl K 264Display key. 265. 266.It Fl O Ar outsep 267Field separator string between key and value. 268Defaults to a single tab 269.Pq Sq \et . 270. 271.It Fl S Ar visitem 272Specify items to 273.Xr strsvisx 3 274encode. 275The 276.Ar visitem 277option-argument is a character specifying if the key 278.Pq Ar k , 279the value 280.Pq Ar v 281or both 282.Pq Ar b 283should be encoded. 284. 285.It Fl V 286Display value. 287. 288.It Fl X Ar extravis 289When encoding items with 290.Fl S 291option also encode characters in 292.Ar extravis , 293per 294.Xr strsvisx 3 . 295. 296.El 297.Pp 298.Bd -ragged -offset indent 299(If neither of 300.Fl K 301or 302.Fl V 303is given, both options are enabled.) 304.Ed 305. 306.Pp 307Write mode specific options are: 308.Bl -tag -width Fl -offset indent 309. 310.It Fl C 311Create new database, and truncate existing databases. 312. 313.It Fl D 314Allow duplicate entries in 315.Sy btree 316databases. 317(Requires 318.Fl R 319to be useful.) 320. 321.It Fl F Ar insep 322Input field separator string between key and value used when parsing 323.Ar infile . 324Defaults to a single space 325.Pq Sq \ . 326. 327.It Fl m Ar mode 328Octal mode of created database. 329Defaults to 330.Sq 0644 . 331. 332.It Fl P Ar pagesize 333Set the page size of the table to 334.Ar pagesize 335bytes. 336If set to 337.Sq 0 , 338a database-specific default is determined, 339based on the block-size of the underlying file-system. 340Defaults to 341.Sq 4096 . 342. 343.It Fl R 344Overwrite existing entries. 345If not specified, writing to an existing entry raises an error. 346. 347.El 348. 349.Sh SEE ALSO 350.Xr vis 1 , 351.Xr btree 3 , 352.Xr db 3 , 353.Xr hash 3 , 354.Xr strsvisx 3 , 355.Xr strunvisx 3 356.\" .Xr makemap 8 357. 358.Sh HISTORY 359The 360.Nm 361command appeared in 362.Nx 2.0 . 363. 364.Sh AUTHORS 365.An Luke Mewburn 366.Aq lukem@NetBSD.org . 367