Sub topic 5
Core CLI command groups
This chapter assumes you have installed the CLI, authenticated, and know how profiles work (earlier chapters). It also assumes you know what jobs, clusters, and Unity Catalog objects are in the workspace. Here you learn how the CLI is organized, so you can find the right command without memorizing a list.
How commands are structured
The Databricks CLI wraps the REST API. Most commands follow this shape:
databricks <group> <subcommand> [positional arguments] [flags]A group is a family of related operations, such as clusters or jobs. A subcommand is a verb, such as list, get, create, delete, or start. Subcommand names use kebab-case (run-now, list-runs). They map closely to API operation names, so API documentation helps you guess the CLI name.
Discovering commands
You do not need to memorize groups. The CLI documents itself at every level:
databricks --help
databricks jobs --help
databricks jobs run-now --helpThe first command lists all groups. The second lists the subcommands of jobs. The third shows the arguments and flags of one subcommand. Check the third one before you script a command, because it states which values are positional and which are flags.
Common groups
| Group | Manages | Typical subcommands |
|---|---|---|
| `current-user` | The identity the CLI uses | `me` |
| `clusters` | All-purpose and job clusters | `list`, `get`, `start`, `restart`, `delete` |
| `jobs` | Job definitions and runs | `list`, `get`, `create`, `run-now`, `list-runs`, `get-run`, `cancel-run` |
| `workspace` | Notebooks, folders, files | `list`, `export`, `import`, `mkdirs`, `delete` |
| `fs` | DBFS paths and Unity Catalog volumes | `ls`, `cp`, `cat`, `rm`, `mkdir` |
| `warehouses` | SQL warehouses | `list`, `get`, `start`, `stop` |
| `catalogs`, `schemas`, `tables` | Unity Catalog objects | `list`, `get` |
| `secrets` | Secret scopes and secrets | `list-scopes`, `create-scope`, `put-secret` |
| `pipelines` | Lakeflow Declarative Pipelines | `list-pipelines`, `get`, `start-update` |
| `bundle` | Asset Bundles | `validate`, `deploy`, `run`, `destroy` |
| `api` | Any REST endpoint | `get`, `post` (covered in a later chapter) |
The exact set of groups depends on your CLI version, so run databricks --help to see what you have.
Reading resources
Read-only commands are the safest place to start. Each one prints a text table by default.
databricks clusters list
databricks clusters get <cluster-id>
databricks jobs get 123
databricks warehouses list
databricks workspace list /Users/<your-user-name>The ID in clusters get and jobs get is a positional argument, not a flag. For a Unity Catalog walk from top to bottom, each level takes the parent name as its argument:
databricks catalogs list
databricks schemas list <catalog>
databricks tables list <catalog> <schema>Changing resources
Commands that create or update objects usually take a request body. You can pass it inline or from a file with --json:
databricks secrets create-scope demo-scope
databricks clusters start <cluster-id>
databricks jobs run-now 123 --json '{"job_parameters": {"env": "dev"}}'The JSON uses the same field names as the REST API. This means any example in the API reference translates directly into a --json payload. To keep a long body out of your shell history, put it in a file and pass --json @body.json.
Some commands also expose individual fields as flags. When both a flag and --json are available, check --help to see which one takes precedence before you combine them.
Waiting and `--no-wait`
Many commands that start long operations block until the operation reaches a stable state. For example, clusters start waits until the cluster is running, and jobs run-now waits until the run finishes. Two flags control this:
--no-waitreturns as soon as the request is accepted.--timeout <duration>changes how long the CLI waits before giving up.
databricks jobs run-now 123 --no-wait -o jsonWith --no-wait, the output is JSON that includes the run_id. You can then poll the run yourself, which is the pattern the jobs API chapter builds on. Blocking is convenient at a terminal. In a pipeline, --no-wait plus your own polling gives you control over timeouts and logging.
Global flags
Every command accepts a few flags that apply across groups:
--profile(or-p) selects an entry from~/.databrickscfg.--output(or-o) choosestextorjson.--debugprints request and response details, which helps when a command fails and the message is unclear.
databricks clusters list --profile staging -o jsonAlways set --profile explicitly in scripts. Without it, the CLI uses the default profile or environment variables, and a script can act on the wrong workspace.
Working with files
The fs group reads and writes DBFS paths and Unity Catalog volumes. Paths use the dbfs:/ prefix, and volumes live under dbfs:/Volumes/<catalog>/<schema>/<volume>/:
databricks fs ls dbfs:/Volumes/main/default/landing
databricks fs cp ./sales.csv dbfs:/Volumes/main/default/landing/sales.csv
databricks fs cat dbfs:/Volumes/main/default/landing/sales.csvWithout the dbfs:/ prefix, the CLI treats a path as local. Copying in the wrong direction is a common mistake, so the source comes first and the destination second, as with cp.
The workspace group works on workspace paths such as notebooks, which are not files on DBFS:
databricks workspace export /Users/<your-user-name>/etl --format SOURCE
databricks workspace list /Users/<your-user-name>Common errors
- Wrong identity or workspace. Run
databricks current-user me --profile <name>first. The returned user name and host tell you which workspace you will hit. - Permission denied. The CLI acts as your user or service principal. A
PERMISSION_DENIEDresponse means that identity lacks access to the object, not that the command is wrong. - Resource does not exist. Job and cluster IDs are different in each workspace. An ID copied from a dev workspace fails in prod.
- Unknown command. Groups and subcommands change between CLI versions. Update the CLI and check
--helpbefore assuming a command is removed. - Confusing positional arguments and flags.
jobs run-now 123works.jobs run-now --job-id 123may not, depending on the version. Read the--helpoutput for the exact form.
Putting it together
This short script checks the identity, lists running clusters, and starts a job without blocking:
#!/usr/bin/env bash
set -euo pipefail
PROFILE="dev"
databricks current-user me --profile "$PROFILE" -o json | jq -r '.userName'
databricks clusters list --profile "$PROFILE" -o json \
| jq -r '.[] | select(.state == "RUNNING") | .cluster_name'
databricks jobs run-now 123 --profile "$PROFILE" --no-wait -o json \
| jq -r '.run_id'set -euo pipefail stops the script on the first failed command, on unset variables, and on failures inside pipes. This matters for automation, where a silent failure can make a later command run against bad input.
Exercise
You want a script to start job 123 in the workspace behind the profile "prod", get the run ID, and continue without waiting for the run to finish. Which command do you use, and why should the profile be explicit?
Show answer
Run databricks jobs run-now 123 --profile prod --no-wait -o json and read run_id from the JSON output, for example with jq -r '.run_id'. --no-wait makes the command return once the run is accepted, and -o json gives stable output to parse. The profile is explicit so the script cannot silently fall back to a default profile or environment variables and start the job in the wrong workspace.
Exercise
A teammate says databricks fs cp sales.csv /Volumes/main/default/landing/sales.csv ran without the file appearing in the volume. What is the likely cause, and what is the fix?
Show answer
Without the dbfs:/ prefix, the CLI treats the destination as a local path, so the copy stayed on the local machine. Use databricks fs cp sales.csv dbfs:/Volumes/main/default/landing/sales.csv and confirm with databricks fs ls dbfs:/Volumes/main/default/landing.