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.gdbmThis 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 valueExample:
shstore name "John Doe" store email "[email protected]"Fetch/Read:
shfetch keyExample:
shfetch nameOutput:
John DoeReplace/Update:
shstore key new_valueExample:
shstore email "[email protected]"Delete:
shdelete keyExample:
shdelete nameList all keys:
shfirstkey nextkeyExample:
shfirstkey nextkeyQuit
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 "[email protected]"
gdbmtool> fetch name
John Doe
gdbmtool> store email "[email protected]"
gdbmtool> fetch email
[email protected]
gdbmtool> delete name
gdbmtool> fetch name
gdbm_fetch: No record found
gdbmtool> firstkey
email
gdbmtool> quit
Key Points:
- File Creation: If
mydatabase.gdbmdoes not exist, it will be created when you startgdbmtool. - Commands: You can perform CRUD operations directly in the terminal using the
store,fetch, anddeletecommands. - Key Navigation: The
firstkeyandnextkeycommands 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.
No comments:
Post a Comment
If you have any doubts, please let me know.