HBase Shell Commands with Examples

โšก Smart Summary

HBase shell commands let you manage tables and data directly from an interactive prompt, grouped into general commands, table management commands such as create and drop, data manipulation commands such as put and get, and cluster replication commands.

  • ๐Ÿ–ฅ๏ธ General commands: status, version, table_help, and whoami report cluster state and user information.
  • ๐Ÿ—‚๏ธ Table management: create, list, describe, disable, enable, drop, and alter build and reshape tables.
  • โœ๏ธ Data manipulation: put, get, delete, deleteall, truncate, count, and scan read and write cell values.
  • ๐Ÿ” Cluster replication: add_peer, remove_peer, start_replication, and stop_replication manage data replication.
  • โณ TTL attribute: Time To Live expires column-family rows automatically after a set number of seconds.
  • ๐Ÿค– AI assist: AI assistants generate and explain HBase shell commands from plain-language prompts.

HBase shell commands with examples for tables, data, and cluster replication

How to Interact with HBase Using Shell Commands and Java API

After a successful installation of HBase on top of Hadoop, we get an interactive shell to execute various commands and perform several operations. Using these commands, we can perform multiple operations on data tables that give better data storage efficiency and flexible interaction for the client.

We can interact with HBase in two ways:

  • HBase interactive shell mode, and
  • Through Java API.

In HBase, interactive shell mode is used to interact with HBase for table operations, table management, and data modeling. Using the Java API model, we can perform all types of table and data operations in HBase. We can interact with HBase using both these methods. The only difference between the two is that the Java API uses Java code to connect with HBase, while shell mode uses shell commands to connect with HBase.

Quick recap of HBase before we proceed:

  • HBase uses Hadoop files as a storage system to store large amounts of data. HBase consists of Master Servers and Region Servers.
  • The data that is going to be stored in HBase will be in the form of regions. Further, these regions will be split up and stored in multiple region servers.
  • These shell commands allow the programmer to define table schemas and data operations using complete shell mode interaction.
  • Whichever command we use, it is going to reflect in the HBase data model.
  • We use HBase shell commands in operating system script interpreters like the Bash shell.
  • The Bash shell is the default command interpreter for most Linux and Unix operating system distributions.
  • HBase advanced versions provide shell commands with JRuby-style object-oriented references for tables.
  • Table reference variables can be used to perform data operations in HBase shell mode.

For example:

  • In this tutorial, we have created a table in which ‘education’ represents the table name and corresponds to the column name “guru99”.
  • In some commands, “guru99” itself represents a table name.

General commands

In HBase, general commands are categorized into the following commands:

  • Status
  • Version
  • Table_help ( scan, drop, get, put, disable, etc.)
  • Whoami

To enter into the HBase shell command, first of all, we have to execute the code as mentioned below.

hbase Shell

Once we enter into the HBase shell, we can execute all the shell commands mentioned below. With the help of these commands, we can perform all types of table operations in the HBase shell mode. The interactive shell prompt appears as shown below:

HBase interactive shell prompt opened with the hbase shell command

Let us look into all of these commands and their usage one by one with an example.

Status

Syntax:status

This command will give details about the system status, like the number of servers present in the cluster, the active server count, and the average load value. You can also pass particular parameters depending on how detailed a status you want to know about the system. The parameters can be ‘summary’, ‘simple’, or ‘detailed’; the default parameter provided is “summary”.

Below, we have shown how you can pass different parameters to the status command. If we observe the below screenshot, we will get a better idea.

hbase(main):001:0>status
hbase(main):002:0>status 'simple'
hbase(main):003:0>status 'summary'
hbase(main):004:0> status 'detailed'

The status output is shown below:

HBase shell status command output showing live servers, dead servers, and average load

When we execute this status command, it gives information about the number of servers present, dead servers, and the average load of the server. Here, the screenshot shows information like 1 live server, 1 dead server, and a 7.0000 average load.

Version

Syntax: version

The version output is shown below:

HBase shell version command showing the installed HBase version

  • This command will display the currently used HBase version in command mode.
  • If you run the version command, it will give output as shown above.

Table help

Syntax:table_help

The table_help output is shown below:

HBase shell table_help output listing create and get_table command usage

This command guides:

  • What table-referenced commands are and how to use them.
  • It will provide different HBase shell command usages and their syntaxes.
  • Here, in the screenshot above, it shows the syntax for the “create” and “get_table” commands with their usage. We can manipulate the table via these commands once the table gets created in HBase.
  • It will give table manipulation commands like put, get, and all other command information.

whoami

Syntax: Whoami

The whoami output is shown below:

HBase shell whoami command returning the current hduser and groups

This command “whoami” is used to return the current HBase user information from the HBase cluster. It will provide information like:

  • Groups present in HBase.
  • The user information; for example, in this case “hduser” represents the user name as shown in the screenshot.

TTL(Time To Live) โ€“ Attribute

In HBase, column families can be set to time values in seconds using TTL. HBase will automatically delete rows once the expiration time is reached. This attribute applies to all versions of a row, even the current version.

The TTL time encoded in HBase for the row is specified in UTC. This attribute is used with table management commands. Important differences between TTL handling and Column family TTLs are below:

  • Cell TTLs are expressed in units of milliseconds instead of seconds.
  • A cell TTL cannot extend the effective lifetime of a cell beyond a Column Family level TTL setting.

Tables Managements commands

These commands will allow programmers to create tables and table schemas with rows and column families. The following are the Table Management commands:

  • Create
  • List
  • Describe
  • Disable
  • Disable_all
  • Enable
  • Enable_all
  • Drop
  • Drop_all
  • Show_filters
  • Alter
  • Alter_status

Let us look into various command usages in HBase with an example.

Create

Syntax: create <tablename>, <columnfamilyname>

Example:-

hbase(main):001:0> create 'education' ,'guru99'
0 rows(s) in 0.312 seconds
=>Hbase::Table โ€“ education

The create command result is shown below:

HBase shell create command building the education table with the guru99 column family

The above example explains how to create a table in HBase with the specified name given according to the specifications for each column family. In addition to this, we can also pass some table-scope attributes into it. In order to check whether the table ‘education’ is created or not, we use the “list” command below. See also creating HBase tables with Java and shell.

List

Syntax:list

The list output is shown below:

HBase shell list command showing eight existing tables in HBase

  • The “list” command will display all the tables that are present or created in HBase.
  • The output shown in the above screenshot is currently showing the existing tables in HBase.
  • Here, in this screenshot, it shows that there are a total of 8 tables present inside HBase.
  • We can filter output values from tables by passing optional regular expression parameters.

Describe

Syntax:describe <table name>
hbase(main):010:0>describe 'education'

The describe output is shown below:

HBase shell describe command output detailing the education table column families

This command describes the named table.

  • It will give more information about the column families present in the mentioned table.
  • In our case, it gives the description of the table “education”.
  • It will give information about the table name with column families, associated filters, versions, and some more details.

disable

Syntax: disable <tablename>
hbase(main):011:0>disable 'education'

The disable output is shown below:

HBase shell disable command taking the education table offline

  • This command will start disabling the named table.
  • If a table needs to be deleted or dropped, it has to be disabled first.

Here, in the above screenshot, we are disabling the table education.

disable_all

 Syntax: disable_all<"matching regex"
  • This command will disable all the tables matching the given regex.
  • The implementation is the same as the drop command (except for adding a regex for matching).
  • Once the table gets disabled, the user is able to delete the table from HBase.
  • Before deleting or dropping a table, it should be disabled first.

Enable

Syntax: enable <tablename>
hbase(main):012:0>enable 'education'

The enable output is shown below:

HBase shell enable command re-activating the disabled education table

  • This command will start enabling the named table.
  • Whichever table is disabled, to retrieve it back to its previous state, we use this command.
  • If a table is disabled in the first instance and not deleted or dropped, and if we want to reuse the disabled table, then we have to enable it by using this command.
  • Here, in the above screenshot, we are enabling the table “education”.

show_filters

Syntax: show_filters

The show_filters output is shown below:

HBase shell show_filters output listing available HBase filters

This command displays all the filters present in HBase, like ColumnPrefixFilter, TimestampsFilter, PageFilter, FamilyFilter, etc.

drop

Syntax:drop <table name>
hbase(main):017:0>drop 'education'

The drop output is shown below:

HBase shell drop command deleting the disabled education table

We have to observe the below points for the drop command:

  • To delete the table present in HBase, first we have to disable it.
  • To drop the table present in HBase, first we have to disable it.
  • So, to either drop or delete a table, first the table should be disabled using the disable command.
  • Here, in the above screenshot, we are dropping the table “education”.
  • Before execution of this command, it is necessary that you disable the table “education”.

drop_all

Syntax: drop_all<"regex">
  • This command will drop all the tables matching the given regex.
  • Tables have to be disabled first, before executing this command, using disable_all.
  • Tables with regex matching expressions are going to be dropped from HBase.

is_enabled

Syntax: is_enabled 'education'

This command will verify whether the named table is enabled or not. Usually, there is a little confusion between the “enable” and “is_enabled” command actions, which we clear up here:

  • Suppose a table is disabled; to use that table, we have to enable it by using the enable command.
  • The is_enabled command will check whether the table is enabled or not.

alter

Syntax: alter <tablename>, NAME=><column familyname>, VERSIONS=>5

This command alters the column family schema. To understand what exactly it does, we have explained it here with an example.

Examples: In these examples, we are going to perform alter command operations on tables and on their columns. We will perform operations like:

  • Altering single and multiple column family names.
  • Deleting column family names from a table.
  • Several other operations using scope attributes with a table.

To change or add the ‘guru99_1’ column family in table ‘education’ from the current value to keep a maximum of 5 cell VERSIONS. Here, “education” is the table name created with the column name “guru99” previously. With the help of an alter command, we are trying to change the column family schema to guru99_1 from guru99, as shown below:

HBase shell alter command changing the education table column family to guru99_1

hbase> alter 'education', NAME='guru99_1', VERSIONS=>5

You can also operate the alter command on several column families as well. For example, we will define two new columns for our existing table “education”, as shown below:

HBase shell alter command adding two new column families guru99_2 and guru99_3

 hbase> alter 'edu', 'guru99_1', {NAME => 'guru99_2', IN_MEMORY => true}, {NAME => 'guru99_3', VERSIONS => 5}
  • We can change more than one column schema at a time using this command.
  • guru99_2 and guru99_3, as shown in the above screenshot, are the two new column names that we have defined for the table education.
  • We can see the way of using this command in the previous screenshot.

In this step, we will see how to delete a column family from the table. To delete the ‘f1’ column family in table ‘education’, use one of these commands below. The result is shown in the screenshot that follows:

HBase shell alter command deleting a column family from the education table

hbase> alter 'education', NAME => 'f1', METHOD => 'delete'
hbase> alter 'education', 'delete' =>' guru99_1'

In this command, we are trying to delete the column space named guru99_1 that we previously created in the first step. As shown in the below screenshots, it shows two steps: how to change a table scope attribute and how to remove the table scope attribute.

HBase shell alter command setting the MAX_FILESIZE table-scope attribute

Syntax: alter <'tablename'>, MAX_FILESIZE=>'132545224'

Step 1) You can change table-scope attributes like MAX_FILESIZE, READONLY, MEMSTORE_FLUSHSIZE, DEFERRED_LOG_FLUSH, etc. These can be put at the end; for example, to change the max size of a region to 128MB or any other memory value, we use this command.

Usage:

  • We can use MAX_FILESIZE with the table as a scope attribute, as above.
  • The number represented in MAX_FILESIZE is in terms of memory in bytes.

NOTE: The MAX_FILESIZE table scope will be determined by some attributes present in HBase. MAX_FILESIZE also comes under table scope attributes.

Step 2) You can also remove a table-scope attribute using the table_att_unset method. See the command below:

alter 'education', METHOD => 'table_att_unset', NAME => 'MAX_FILESIZE'
  • The above screenshot shows the altered table name with scope attributes.
  • The method table_att_unset is used to unset attributes present in the table.
  • In the second instance, we are unsetting the attribute MAX_FILESIZE.
  • After execution of the command, it will simply unset the MAX_FILESIZE attribute from the “education” table.

alter_status

 Syntax: alter_status 'education'

The alter_status output is shown below:

HBase shell alter_status command showing one of one regions updated

  • Through this command, you can get the status of the alter command.
  • It indicates the number of regions of the table that have received the updated schema. You pass the table name.
  • Here, in the above screenshot, it shows 1/1 regions updated. It means that it has updated one region. After that, if it is successful, it will display the comment “done”.

Data manipulation commands

These commands work on the table for data manipulations, such as putting data into a table, retrieving data from a table, and deleting schema, etc. The commands that come under these are:

  • Count
  • Put
  • Get
  • Delete
  • Delete all
  • Truncate
  • Scan

Let us look into these command usages with an example. See also reading and writing HBase data.

Count

Syntax: count <'tablename'>, CACHE =>1000
  • The command will retrieve the count of the number of rows in a table. The value returned by this one is the number of rows.
  • The current count is shown per every 1000 rows by default.
  • The count interval may be optionally specified.
  • The default cache size is 10 rows.
  • The count command will work fast when it is configured with the right cache.

Example:

hbase> count 'guru99', CACHE=>1000

The count output is shown below:

HBase shell count command returning the row count of the guru99 table

This example count fetches 1000 rows at a time from the “guru99” table. We can make the cache a lower value if the table consists of more rows. But by default, it will fetch one row at a time.

hbase>count 'guru99', INTERVAL => 100000
hbase> count 'guru99', INTERVAL =>10, CACHE=> 1000

Suppose the table “guru99” has some table reference, like say g. We can run the count command on the table reference also, like below:

hbase>g.count INTERVAL=>100000
hbase>g.count INTERVAL=>10, CACHE=>1000

Put

Syntax:  put <'tablename'>,<'rowname'>,<'columnvalue'>,<'value'>

This command is used for the following things:

  • It will put a cell ‘value’ at a defined or specified table or row or column.
  • It will optionally coordinate a time stamp.

Example: Here, we are placing values into table “guru99” under row r1 and column c1.

hbase> put 'guru99', 'r1', 'c1', 'value', 10

We have placed three values, 10, 15, and 30, in table “guru99”, as shown in the screenshot below.

HBase shell put command inserting values 10, 15, and 30 into the guru99 table

Suppose the table “guru99” has some table reference, like say g. We can also run the command on the table reference, like:

hbase> g.put 'guru99', 'r1', 'c1', 'value', 10

The output will be as shown in the above screenshot after placing values into “guru99”. To check whether the input value is correctly inserted into the table, we use the “scan” command. In the below screenshot, we can see the values are inserted correctly.

HBase shell scan output confirming the values inserted into the guru99 table

Code Snippet: For Practice

create 'guru99', {NAME=>'Edu', VERSIONS=>213423443}
put 'guru99', 'r1', 'Edu:c1', 'value', 10
put 'guru99', 'r1', 'Edu:c1', 'value', 15
put 'guru99', 'r1', 'Edu:c1', 'value', 30

From the code snippet, we are doing these things:

  • Here, we are creating a table named ‘guru99’ with the column name as “Edu”.
  • By using the “put” command, we are placing values into row name r1 in column “Edu” into table “guru99”.

Get

Syntax: get <'tablename'>, <'rowname'>, {< Additional parameters>}

Here, <Additional Parameters> include TIMERANGE, TIMESTAMP, VERSIONS, and FILTERS. By using this command, you will get a row or cell contents present in the table. In addition to that, you can also add additional parameters to it, like TIMESTAMP, TIMERANGE, VERSIONS, FILTERS, etc., to get a particular row or cell content.

The get output below returns row r1 and column c1 values:

HBase shell get command returning row r1 and column c1 from the guru99 table

Examples:-

hbase> get 'guru99', 'r1', {COLUMN => 'c1'}

For table “guru99”, row r1 and column c1 values will display using this command, as shown in the above screenshot.

hbase> get 'guru99', 'r1'

For table “guru99”, row r1 values will be displayed using this command.

hbase> get 'guru99', 'r1', {TIMERANGE => [ts1, ts2]}

For table “guru99”, row r1 values in the time range ts1 to ts2 will be displayed using this command.

hbase> get 'guru99', 'r1', {COLUMN => ['c1', 'c2', 'c3']}

For table “guru99”, row r1 and column families c1, c2, and c3 values will be displayed using this command.

Delete

Syntax:delete <'tablename'>,<'row name'>,<'column name'>
  • This command will delete the cell value at a defined table of row or column.
  • Delete must and should match the deleted cell’s coordinates exactly.
  • When scanning, a delete cell suppresses older versions of values.

Example: The delete command below removes cell r1, c1 from the guru99 table:

HBase shell delete command removing cell r1 c1 from the guru99 table

hbase(main):)020:0> delete 'guru99', 'r1', 'c1''.
  • The above execution will delete row r1 from column family c1 in table “guru99”.
  • Suppose the table “guru99” has some table reference, like say g.
  • We can run the command on the table reference also, like hbase> g.delete ‘guru99’, ‘r1’, ‘c1′”.

deleteall

Syntax: deleteall <'tablename'>, <'rowname'>
  • This command will delete all cells in a given row.
  • We can optionally define column names and a time stamp in the syntax.

Example:- The deleteall command below removes every cell in row r1:

HBase shell deleteall command removing all cells in row r1 of the guru99 table

hbase>deleteall 'guru99', 'r1', 'c1'

This will delete all the rows and columns present in the table. Optionally, we can mention column names in that.

Truncate

Syntax:  truncate <tablename>

The truncate command below empties the table while keeping its schema:

HBase shell truncate command disabling, dropping, and recreating the guru99 table

After the truncate of an HBase table, the schema will be present but not the records. This command performs 3 functions; those are listed below:

  • Disables the table if it already exists.
  • Drops the table if it already exists.
  • Recreates the mentioned table.

Scan

Syntax: scan <'tablename'>, {Optional parameters}

This command scans the entire table and displays the table contents.

  • We can pass several optional specifications to this scan command to get more information about the tables present in the system.
  • Scanner specifications may include one or more of the following attributes.
  • These are TIMERANGE, FILTER, TIMESTAMP, LIMIT, MAXLENGTH, COLUMNS, CACHE, STARTROW, and STOPROW.
scan 'guru99'

The scan output is shown below:

HBase shell scan command displaying rows r1, r2, and r3 of the guru99 table

In the above screenshot:

  • It shows the “guru99” table with the column name and values.
  • It consists of three row values, r1, r2, and r3, for the single column value c1.
  • It displays the values associated with the rows.

Examples:- The different usages of the scan command:

Command Usage
scan ‘.META.’, {COLUMNS => ‘info:regioninfo’} It displays all the metadata information related to columns that are present in the tables in HBase.
scan ‘guru99’, {COLUMNS => [‘c1’, ‘c2’], LIMIT => 10, STARTROW => ‘xyz’} It displays contents of table guru99 with their column families c1 and c2, limiting the values to 10.
scan ‘guru99’, {COLUMNS => ‘c1’, TIMERANGE => [1303668804, 1303668904]} It displays contents of guru99 with its column name c1 with the values present in between the mentioned time range attribute value.
scan ‘guru99’, {RAW => true, VERSIONS =>10} In this command, RAW=> true provides an advanced feature, like displaying all the cell values present in the table guru99.

Code Example: First, create a table and place values into the table. The input is shown in the screenshot below:

HBase shell input creating the guru99 table and inserting versioned values before a raw scan

create 'guru99', {NAME=>'e', VERSIONS=>2147483647}
put 'guru99', 'r1', 'e:c1', 'value', 10
put 'guru99', 'r1', 'e:c1', 'value', 12
put 'guru99', 'r1', 'e:c1', 'value', 14
delete 'guru99', 'r1', 'e:c1', 11

If we run the scan command:

Query: scan 'guru99', {RAW=>true, VERSIONS=>1000}

It will display the output shown below:

HBase shell raw scan output showing multiple cell versions including a deleted value

The output shown in the above screenshot gives the following information:

  • Scanning the guru99 table with attributes RAW=>true, VERSIONS=>1000.
  • Displaying rows with column families and values.
  • In the third row, the values displayed show the deleted value present in the column.
  • The output displayed by it is random; it cannot be in the same order as the values that we inserted in the table.

Cluster Replication Commands

  • These commands work on the cluster set-up mode of HBase.
  • For adding and removing peers to a cluster, and to start and stop replication, these commands are used in general.
Command Functionality
add_peer Adds peers to a cluster to replicate.
hbase> add_peer ‘3’, zk1,zk2,zk3:2182:/hbase-prod
remove_peer Stops the defined replication stream and deletes all the metadata information about the peer.
hbase> remove_peer ‘1’
start_replication Restarts all the replication features.
hbase> start_replication
stop_replication Stops all the replication features.
hbase>stop_replication

FAQs

Type exit or quit and press Enter to leave the interactive HBase shell and return to the operating-system prompt. You open the shell with the hbase shell command. Neither exit nor quit stops the HBase service; they only end the shell session.

Yes. Pipe commands in non-interactively, for example echo “list” | hbase shell, or run a saved file with hbase shell script.txt. Because the shell is JRuby based, you can also embed Ruby logic and loops inside .rb script files.

The shell is an interactive JRuby prompt for quick manual commands and administration. The Java API, using Connection, Admin, and Table, is for applications that create tables and read or write data programmatically. Both reach the same HBase cluster and data.

The “Table already exists” error appears when create repeats an existing name, and “Table not disabled” appears when you drop or alter without disabling first. Run disable ‘table’ before drop or alter, and use exists ‘table’ to check a name before creating it.

An HBase column family keeps a limited number of timestamped versions per cell, historically three and one in newer releases. Set the count with VERSIONS at create or alter time, and request older versions using {VERSIONS => n} on a get or scan command.

A table reference variable is a shell object returned by g = get_table ‘guru99’. You then call methods on it, such as g.put, g.get, or g.count, instead of repeating the table name. It is a convenient JRuby-style shortcut in the HBase shell.

AI coding assistants and large language models generate HBase shell commands from plain-language requests, explain unfamiliar options such as scan filters or TTL, and help debug errors. Machine learning also analyzes cluster metrics to guide replication and region tuning, though an engineer should verify each command.

Yes. GitHub Copilot suggests HBase shell commands and JRuby scripts from a short comment, including create, put, scan, and alter examples. Review its output for the correct table name, column families, and syntax such as VERSIONS before running it on a real cluster.

Summarize this post with: