To interact with a GDBM (GNU Database Manager) database via the command line, you can use the gdbmtool
utility, which is included with the GDBM package. This tool allows you to perform basic CRUD (Create, Read, Update, Delete) operations on a GDBM database directly from the terminal.
Accessing GDBM via Command Line with gdbmtool
Open a Terminal and Start
gdbmtool
:shgdbmtool mydatabase.gdbm
This will open the GDBM database named
mydatabase.gdbm
. If the file doesn't exist, it will be created.Basic Commands in
gdbmtool
:Insert/Create:
shstore key value
Example:
shstore name "John Doe" store email "johndoe@example.com"
Fetch/Read:
shfetch key
Example:
shfetch name
Output:
John Doe
Replace/Update:
shstore key new_value
Example:
shstore email "john.doe@newdomain.com"
Delete:
shdelete key
Example:
shdelete name
List all keys:
shfirstkey nextkey
Example:
shfirstkey nextkey
Quit
gdbmtool
:shquit
Example Session
Here's a complete example of a session in gdbmtool
:
sh$ gdbmtool mydatabase.gdbm
GDBM database opened.
gdbmtool> store name "John Doe"
gdbmtool> store email "johndoe@example.com"
gdbmtool> fetch name
John Doe
gdbmtool> store email "john.doe@newdomain.com"
gdbmtool> fetch email
john.doe@newdomain.com
gdbmtool> delete name
gdbmtool> fetch name
gdbm_fetch: No record found
gdbmtool> firstkey
email
gdbmtool> quit
Key Points:
- File Creation: If
mydatabase.gdbm
does not exist, it will be created when you startgdbmtool
. - Commands: You can perform CRUD operations directly in the terminal using the
store
,fetch
, anddelete
commands. - Key Navigation: The
firstkey
andnextkey
commands allow you to iterate over all the keys in the database.
Additional Options
You can explore additional options and features of gdbmtool
by typing help
within the tool:
shgdbmtool> help
This will display a list of available commands and their descriptions.
Comments
Post a Comment
If you have any doubts, please let me know.