Link Search Menu Expand Document
Start for Free

Command Line Interface

This page describes the command line interface (CLI) to interact with Stardog. Please view Stardog and Stardog Admin CLI Reference Manuals for a full description of all CLI commands.

Page Contents
  1. Overview
  2. Security Considerations
  3. Command Groups
  4. Connecting to a Database
    1. Specifying the Server
    2. Connection Options
    3. Fully Qualified Connection Strings
  5. Autocomplete
  6. Installing Man Pages Locally

Overview

Stardog’s command-line interface (CLI) comes in two parts:

  1. stardog-admin: administrative client
  2. stardog: a user’s client

The admin and user tools operate on local or remote databases using HTTP. These CLI tools are self-documenting, and their help output is their canonical documentation. In other words, if there is a conflict between this documentation and the output of the CLI tools’ help command, the CLI output is correct.

Security Considerations

We divide administrative functionality into two CLI programs for reasons of security: stardog-admin will need, in production environments, to have considerably tighter access restrictions than stardog.

For usability, Stardog provides a default user admin and password admin in stardog-admin commands if no user or password are given. This is insecure; before any serious use of Stardog is contemplated, read the Security section at least twice, and then–minimally–change the administrative password to something we haven’t published online!

Command Groups

The CLI tools use “command groups” to make CLI subcommands easier to find. To print help for a particular command group, just ask for help:

stardog help [command_group_name]

See the Stardog CLI Reference and Stardog Admin CLI Reference for the canonical list of commands.

The main help command for either CLI tool will print a list of the command groups:

$ stardog help                                                                               
usage: stardog [ --krb5 ] [ --krb5-disable-rdns ] <command> [ <args> ]

Commands are:
    data        Commands which can modify or dump the contents of a database
    doc         Unstructured document processing
    file        Commands for manipulating rdf files
    graphql     Commands for working with GraphQL
    help        Display help information
    icv         Commands for working with Stardog Integrity Constraint support
    namespace   Commands which work with the namespaces defined for a database
    query       Commands which query a Stardog database
    reasoning   Commands which use the reasoning capabilities of a Stardog database
    tx          Commands for managing transactions
    version     Prints information about this version of Stardog.

See 'stardog help <command>' for more information on a specific command.

To get more information about a particular command, simply issue the help command for it, including its command group:

stardog help query execute

Finally, everything here about command groups, commands, and online help works for stardog-admin.

Connecting to a Database

Most CLI commands operate on a specific Stardog database. The simplest way to specify which database to use is to pass the database name as the command argument:

$ stardog query execute myDb "SELECT * { ?s ?p ?o } LIMIT 10"

This works when Stardog is running on the same machine and listening on the default port (5820).

Specifying the Server

When the server is on a different machine or a non-default port, use the --server option:

$ stardog query execute --server http://myserver:5820 myDb "SELECT * { ?s ?p ?o } LIMIT 10"
$ stardog-admin --server http://myserver:5820 db status myDb

The --server option is available as a global option on all stardog and stardog-admin commands.

Connection Options

Some commands accept connection-level options such as --reasoning, which enables reasoning for the duration of the query:

$ stardog query execute --reasoning myDb "SELECT * { ?s ?p ?o } LIMIT 10"

See the help output for individual commands for the full list of supported options.

Fully Qualified Connection Strings

For stardog commands (not stardog-admin), you can embed the server URL and connection options directly into the database argument as a fully qualified connection string:

{scheme}{host}:{port}/{databaseName};{option}={value}

For example:

  1. http://myserver:5820/myDb — remote server on the default port
  2. http://localhost:12345/myOtherDb — local server on a non-default port
  3. http://169.175.100.5:1111/myDb;reasoning=true — remote server with reasoning enabled

Options are appended as ;-delimited key-value pairs. Key names must be lowercase, and their values are case-sensitive.

Fully qualified connection strings are only supported by stardog commands. For stardog-admin commands, use the --server option to specify the server.

Autocomplete

Stardog also supports CLI autocomplete via bash autocompletion. To install autocomplete for the bash shell, you’ll first want to make sure bash completion is installed.

  • brew install bash-completion
    

    To enable, edit .bash_profile:

    if [ -f `brew --prefix`/etc/bash_completion ]; then
      . `brew --prefix`/etc/bash_completion
    fi
    
  • sudo port install bash-completion
    

    Then, edit .bash_profile

    if [ -f /opt/local/etc/bash_completion ]; then
       . /opt/local/etc/bash_completion
    fi
    
  • sudo apt-get install bash-completion
    

    Now put the Stardog autocomplete script—stardog-completion.sh which is found in your distribution—into your bash_completion.d directory, typically one of /etc/bash_completion.d, /usr/local/etc/bash_completion.d or ~/bash_completion.d.

    Alternately you can put it anywhere you want, but tell .bash_profile about it:

    source ~/.stardog-completion.sh
    
  • sudo yum install bash-completion
    

    Now put the Stardog autocomplete script—stardog-completion.sh which is found in your distribution—into your bash_completion.d directory, typically one of /etc/bash_completion.d, /usr/local/etc/bash_completion.d or ~/bash_completion.d.

    Alternately you can put it anywhere you want, but tell .bash_profile about it:

    source ~/.stardog-completion.sh
    

Installing Man Pages Locally

To install the man pages locally in your Unix-like environment:

$ cp <stardog-installation-directory>/docs/man1/* /usr/local/share/man1
$ cp <stardog-installation-directory>/docs/man8/* /usr/local/share/man8
$ mandb
$ man stardog-admin-server-start