Workspace CLI

You run Databricks workspace CLI subcommands by appending them to databricks workspace.

databricks workspace -h
Usage: databricks workspace [OPTIONS] COMMAND [ARGS]...

  Utility to interact with the Databricks workspace. Workspace paths must be
  absolute and be prefixed with `/`.

Common Options:
  -v, --version  [VERSION]
  -h, --help     Show this message and exit.

Commands:
  delete      Deletes objects from the Databricks workspace. rm and delete are synonyms.
    Options:
        -r, --recursive
  export      Exports a file from the Databricks workspace.
    Options:
      -f, --format FORMAT      SOURCE, HTML, JUPYTER, or DBC. Set to SOURCE by default.
      -o, --overwrite          Overwrites file with the same name as a Workspace file.
  export_dir  Recursively exports a directory from the Databricks workspace.
    Options:
      -o, --overwrite          Overwrites local files with the same names as Workspace files.
  import      Imports a file from local to the Databricks workspace.
    Options:
      -l, --language LANGUAGE  SCALA, PYTHON, SQL, R  [required]
      -f, --format FORMAT      SOURCE, HTML, JUPYTER, or DBC. Set to SOURCE by default.
      -o, --overwrite          Overwrites workspace files with the same names as local files.
  import_dir  Recursively imports a directory to the Databricks workspace.

    Only directories and files with the extensions .scala, .py, .sql, .r, .R,
    .ipynb are imported. When imported, these extensions are stripped off
    the name of the notebook.

    Options:
      -o, --overwrite          Overwrites workspace files with the same names as local files.
      -e, --exclude-hidden-files
  list        Lists objects in the Databricks workspace. ls and list are synonyms.
    Options:
      --absolute               Displays absolute paths.
      -l                       Displays full information including ObjectType, Path, Language
  ls          Lists objects in the Databricks workspace. ls and list are synonyms.
    Options:
      --absolute               Displays absolute paths.
      -l                       Displays full information including ObjectType, Path, Language
  mkdirs      Makes directories in the Databricks workspace.
  rm          Deletes objects from the Databricks workspace. rm and delete are synonyms.
    Options:
        -r, --recursive

List workspace files

databricks workspace ls /Users/example@databricks.com
Usage Logs ETL
Common Utilities
guava-21.0

Import a local directory of notebooks

The databricks workspace import_dir command recursively imports a directory from the local filesystem to the Workspace. Only directories and files with the extensions of .scala, .py, .sql, .r, .R are imported. When imported, these extensions are stripped from the notebook name.

To overwrite existing notebooks at the target path, add the flag -o.

tree
.
├── a.py
├── b.scala
├── c.sql
├── d.R
└── e
databricks workspace import_dir . /Users/example@databricks.com/example
./a.py -> /Users/example@databricks.com/example/a
./b.scala -> /Users/example@databricks.com/example/b
./c.sql -> /Users/example@databricks.com/example/c
./d.R -> /Users/example@databricks.com/example/d
databricks workspace ls /Users/example@databricks.com/example -l
NOTEBOOK   a  PYTHON
NOTEBOOK   b  SCALA
NOTEBOOK   c  SQL
NOTEBOOK   d  R
DIRECTORY  e

Export a workspace folder to the local filesystem

You can export a folder of notebooks from the workspace to the local filesystem. To do this, run:

databricks workspace export_dir /Users/example@databricks.com/example .