Main Page » Getting Started » Command-Line Interface

Command-Line Interface

This page introduces you to the standalone command-line interface (CLI) of BaseX.


The command-line interface can be started as follows:

  • Run one of the basex Start Scripts.
  • If you have installed BaseX on Windows, click on the BaseX Standalone icon.

All operations will be performed with admin permissions (no password needs to be supplied). Various Command-Line Options are available to simplify batch processing. The Start Script can be adjusted for individual purposes (e.g., if the default memory limit is too restrictive).

The standalone CLI must not be used if you perform parallel (concurrent) read and write operations on your databases. See Concurrent Operations for more details.


Create a Database

With the CREATE DB command, a new database can be generated. By default, the new database will be empty, but you can also supply a path to an initial XML document or a directory with multiple resources. A path to a single document can a be local or a remote one.

With the following command, a factbook with a single document will be created:

CREATE DB factbook

By default, databases are stored in the basex/data directory of your project’s home directory. Depending on your Configuration, the location may vary.

Execute a Query

The XQUERY command lets you run a query. The following query returns all country elements of the currently opened database:

XQUERY //country

You can also run queries in files:

RUN /path/to/query.xq

Database Commands

The following command lists all databases that can be opened by the currently logged-in user:


To open an existing database, type OPEN followed by the name of the database, for example:

OPEN factbook

To get information on the currently opened database, type:


You can also address a database within your query with the db:get function:

XQUERY db:get("factbook")//country

To close the current database, type:


To delete a database, type DROP DATABASE followed by the name of the database, for example:


Multiple Resources

One database can contain not only a single, but millions of documents. All documents can have a different structure.

With the following commands, you can create an empty database and add two documents. It is also possible to address resources via URLs:

ADD factbook.xml

Deleting a document from a database is easy, but make sure that the database, which contains the addressed document, is currently opened:

DELETE factbook.xml

Backup and Restore

To back up a database, type:


To restore a database from an existing backup, type:

RESTORE factbook

The backup file is stored in the database directory. It contains the name of the database and a timestamp: [db-name]-[timestamp].zip. If a database is to be restored, and if several backups exist, the backup with the newest timestamp is taken.


To see a brief description of all commands, type:


To see a description of a particular command, type HELP followed by the name of the command, for example:



To exit the command-line interface, type either EXIT or QUIT.


⚡Generated with XQuery