Cassandra provides the Documented Shell commands which are the additional commands apart from the CQL commands that can be used to perform various kinds of operations such as DESCRIBE, SHOW, HELP, COPY, CLS, CAPTURE, and so on.

In this section of the Cassandra Tutorial, we will go through Cassandra Documented shell commands.


1. Cassandra Help Command

Cassandra Help command is used to show the complete commands details of Cassandra.

Command:
cqlsh> help

Output:
cassandra help command cloudduggu


2. Cassandra Clear Command

Cassandra Clear command will clear all previous output from the screen as mentioned in the below example.

Command:
cqlsh> clear

Output:
cassandra clear command cloudduggu


3. Cassandra Capture Command

Cassandra Capture command will capture the output of the command and put it in a file. In the following example, we are running a query to check the existing keyspace name and the output of the query will be captured in the "commandoutput" file that is located at "/home/cloudduggu/apache-Cassandra-4.0.1/". Once the Capture task is completed we can turn off it using "capture off" command as mentioned below.

Command:
cqlsh> capture '/home/cloudduggu/apache-cassandra-4.0.1/commandoutput'
cqlsh> SELECT * FROM system_schema.keyspaces;
cqlsh> capture OFF;

Output:
cassandra capture command cloudduggu

We can verify the output by going to the path "/home/cloudduggu/apache-cassandra-4.0.1". We can see the file name "commandoutput" is created and output is also captured as mentioned in the below screenshot.

cassandra capture command output cloudduggu


4. Cassandra Consistency Command

Cassandra Consistency command is used to check how many nodes in replica will respond to the coordinator node for a task. The consistency level can be changed using this command.

Command:
cqlsh> consistency

Output:
cassandra consistency command cloudduggu


5. Cassandra Copy Command

Cassandra Copy command is used to copy data from Cassandra to a file and from a file to Cassandra table.

5.1 Copy To Command

The Cassandra Copy To Command copies data from the Cassandra table to a file. In the below example we already have a table named emp_name that is present in the Cloudduggu keyspace. Now we will copy the table content to a file name emp_name_output. The command to perform the Cassandra Copy command is mentioned below.

Command:
cqlsh> USE cloudduggu;
CQLSH:cloudduggu> copy emp_name (id, first_name, last_name) TO 'emp_name_output';

We can also give the path of the output file as mentioned in the below command.

CQLSH:cloudduggu> copy emp_name (id, first_name, last_name) TO '/home/cloudduggu/apache-cassandra-4.0.1/bin/emp_name_output';

Output:
cassandra copy command cloudduggu

The file name emp_name_output was created under the /bin directory because we started the cqlsh from /bin only. We can use the cat command to view the content of the file as mentioned in the below screenshot.

cassandra copy command output cloudduggu


5.2 Copy From Command

The Cassandra Copy From Command copies data from the files to the Cassandra table. In the below example we already have emp_name, we will truncate the data from the table and load data from the file emp_name_output using the below command.

Command:
CQLSH:cloudduggu> TRUNCATE TABLE cloudduggu.emp_name;
CQLSH:cloudduggu> copy cloudduggu.emp_name (id, first_name, last_name) FROM '/home/cloudduggu/apache-cassandra-4.0.1/bin/emp_name_output';
CQLSH:cloudduggu> SELECT * FROM cloudduggu.emp_name;

Output:
cassandra copy from command output cloudduggu


6. Cassandra Describe Command

The Cassandra Describe Command is used to show the description of Cluster, Tables, Keyspaces, and so on. In the following section, we will see some of the examples of Cassandra's Describe Command.


6.1 Cassandra Describe Cluster

The Cassandra Describe Cluster command provides detail about the cluster.

Command:
CQLSH:cloudduggu> describe cluster;

Output:
cassandra describe command output cloudduggu


6.2 Cassandra Describe Tables or Table

The Cassandra Describe Tables or Table commands are used to show the detail about the tables. The Describe Tables command will show the list of tables present in the Keyspace and the Describe Table <tablename> command is used to show the description of the table name. In the below example we will use both ways to see the output.

Command:
CQLSH:cloudduggu> describe tables;
CQLSH:cloudduggu> describe table emp_name;

Output:
cassandra describe table command output cloudduggu


6.3 Cassandra Describe Keyspaces

The Cassandra Keyspaces command shows the detail about all the Keyspaces present in the Cassandra Cluster.

Command:
CQLSH:cloudduggu> describe keyspaces;

Output:
cassandra describe keyspaces command output cloudduggu


7. Cassandra Expand Command

The Cassandra Expand command expands the output of a query in a more readable form. The Expand command is used by turning it on using the expand on; and it can be turned off using the expand off; command.

Let's see an example of Cassandra Expand in the below section.

Command:
CQLSH:cloudduggu> expand ON;
CQLSH:cloudduggu> SELECT * FROM emp_name;

Output:
cassandra expand command output cloudduggu

After using Expand, we can use the expand off; command to turn it off as mentioned below.

Command:
CQLSH:cloudduggu> expand OFF;

Output:
cassandra expand off command output cloudduggu


8. Cassandra Show Command

The Cassandra Show command displays the information about the current session, host detail, Version information, and so on.

Command:
CQLSH:cloudduggu> show host;
CQLSH:cloudduggu> show version;
CQLSH:cloudduggu> help show;

Output:
cassandra show command output cloudduggu


9. Cassandra Source Command

We can use the Cassandra Source command to execute multiple commands from a file. In the below following example, we will create a filename name script and put the commands cloudduggu keyspace and Select * from emp_name and we will run this file using the Source command as mentioned in the below snapshot.

Command:
cloudduggu@ubuntu:~/apache-cassandra-4.0.1/bin$ vi script.txt
cloudduggu@ubuntu:~/apache-cassandra-4.0.1/bin$ cat script.txt
USE cloudduggu;
SELECT * FROM emp_name;
cloudduggu@ubuntu:~/apache-cassandra-4.0.1/bin$ ./cqlsh
cqlsh> source '/home/cloudduggu/apache-cassandra-4.0.1/bin/script.txt';

Output:
cassandra source command output cloudduggu