Prev |  | Next

## 29.1. Starting the shell

When used together with a Neo4j server, simply issue the following at the command line:

    ./bin/neo4j-shell

For the full list of options, see the reference in the Shell manual page.

To connect to a running Neo4j database, use Section 29.1.4, “Read-only mode” for local databases and see Section 29.1.1, “Enabling the shell server” for remote databases.

You need to make sure that the shell jar file is on the classpath when you start up your Neo4j instance.

### 29.1.1. Enabling the shell server

Shell is enabled from the configuration of the Neo4j kernel, see Section 23.2, “Server Configuration”. Here’s some sample configurations:

    # Enable the remote shell feature
    remote_shell_enabled = true

    # The default port is 1337, but you can specify something else if you like
    remote_shell_port = 1337

    # If you want to be a little protective of your data,
    # you can also tell the shell to only support read operations
    remote_shell_read_only = true

When using the Neo4j server, see Section 23.2, “Server Configuration” for how to add configuration settings in that case.

There are two ways to start the shell, either by connecting to a remote shell server or by pointing it to a Neo4j store path.

### 29.1.2. Connecting to a shell server

To start the shell and connect to a running server, run:

    neo4j-shell

Alternatively supply `-port` and `-name` options depending on how the remote shell server was enabled. Then you’ll get the shell prompt like this:

    neo4j-sh (0)$

### 29.1.3. Pointing the shell to a path

To start the shell by just pointing it to a Neo4j store path you run the shell jar file. Given that the right neo4j-kernel-<version>.jar and jta jar files are in the same path as your neo4j-shell-<version>.jar file you run it with:

    $ neo4j-shell -path path/to/neo4j-db

### 29.1.4. Read-only mode

By issuing the `-readonly` switch when starting the shell with a store path, changes cannot be made to the database during the session.

    $ neo4j-shell -readonly -path path/to/neo4j-db

### 29.1.5. Run a command and then exit

It is possible to tell the shell to just start, execute a command and then exit. This opens up for uses of background jobs and also handling of huge output of f.ex. an `ls` command where you then could pipe the output to `less` or another reader of your choice, or even to a file.

And even to another neo4j-shell, e.g. for importing a `dump` of another database or cypher result. When used with command mode the shell will not output a welcome message. So some examples of usage:

    $ neo4j-shell -c "cd -a 24 && set name Mattias"
    $ neo4j-shell -c "trav -r KNOWS" | less

### 29.1.6. Pass Neo4j configuration options

By setting the `-config` switch, you can provide a properties file that will be used to configure your Neo4j instance, if started in embedded mode.

    $ neo4j-shell -config conf/neo4j.properties -path mydb

### 29.1.7. Execute a file and then exit

To execute commands from a file and then exit just provide a `-file filename`. This is faster than piping to the shell which still handles the input as if it was user input.

For example reading a dump file directly from the command line and executing it against the given database. For example:

    $ neo4j-shell -file export.cql > result.txt

Supplying `-` as the filename reads from `stdin` instead.

Copyright © 2014 Neo Technology

Prev | Up | Next
| Home |