Skip to main content

fs command group

note

This information applies to Databricks CLI versions 0.205 and above. The Databricks CLI is in Public Preview.

Databricks CLI use is subject to the Databricks License and Databricks Privacy Notice, including any Usage Data provisions.

The fs command group within the Databricks CLI allows you to perform file system operations on volumes in Unity Catalog and the Databricks File System (DBFS).

fs commands require volume paths to begin with dbfs:/Volumes and require directory and file paths in DBFS to begin with dbfs:/.

To perform operations on workspace files in the /Workspace directory, use databricks workspace commands. See workspace command group.

databricks fs cat

Output the contents of a file. Specify the path to the file in DBFS.

databricks fs cat FILE_PATH [flags]

Arguments

FILE_PATH

    The file to output

Options

Global flags

Examples

The following examples output the contents of the file named babynames.csv found in the specified volume's root or in a tmp directory within the DBFS root:

Bash
databricks fs cat dbfs:/Volumes/main/default/my-volume/babynames.csv
databricks fs cat dbfs:/tmp/babynames.csv

The following examples return errors, as they try to output the contents of a directory instead of a file:

Bash
databricks fs cat dbfs:/Volumes/main/default/my-volume
databricks fs cat dbfs:/tmp

databricks fs cp

Copy a directory or a file. Specify the paths to the source directory or file to copy and its destination. You can copy directories and files between the local filesystem and DBFS, and you can copy directories and files between DBFS paths.

The cp command assumes file:/, if file:/ is omitted.

databricks fs cp SOURCE_PATH TARGET_PATH [flags]

Arguments

SOURCE_PATH

    The source directory or file path

TARGET_PATH

    The target directory or file path

Options

--overwrite

    Overwrite existing files

-r, --recursive

    Recursively copy files within a directory

Global flags

Examples

The following examples copy a directory named squirrel-data and its contents, from a local filesystem path to a squirrels directory within the specified volume's root or the DBFS root.

Bash
databricks fs cp /Users/<username>/squirrel-data dbfs:/Volumes/main/default/my-volume/squirrels -r
databricks fs cp /Users/<username>/squirrel-data dbfs:/squirrels -r

The following example copies a file named squirrels.csv from a local filesystem path to a directory named squirrel-data within the specified volume's root or the DBFS root. If the file already exists in the destination, it is overwritten.

Bash
databricks fs cp /Users/<username>/squirrels.csv dbfs:/Volumes/main/default/my-volume/squirrel-data --overwrite
databricks fs cp /Users/<username>/squirrels.csv dbfs:/squirrel-data --overwrite

databricks fs ls

List the contents of a specified directory in a volume or in DBFS.

databricks fs ls DIR_PATH [flags]

Arguments

DIR_PATH

    The directory path

Options

--absolute

    Display absolute paths.

--long, -l

    Displays full information including size, file type and modification time since Epoch in milliseconds.

Global flags

Examples

The following examples list the names of the objects found in the specified volume's root or in the DBFS root:

Bash
databricks fs ls dbfs:/Volumes/main/default/my-volume
databricks fs ls dbfs:/

The following examples list the full (long) information of the objects found in the specified volume's root or in a tmp directory within the DBFS root:

Bash
databricks fs ls dbfs:/Volumes/main/default/my-volume -l
databricks fs ls dbfs:/tmp -l

The following examples list the full information of the objects, and the objects' full paths, found in the specified volume's root or in a tmp directory within the DBFS root:

Bash
databricks fs ls dbfs:/Volumes/main/default/my-volume -l --absolute
databricks fs ls dbfs:/tmp -l --absolute

databricks fs mkdir

Creates a directory. Specify the path to the directory to be created in a volume or in DBFS. If the directory already exists, nothing happens.

databricks fs mkdir DIR_PATH [flags]

Arguments

DIR_PATH

    The directory path to create

Options

Global flags

Examples

The following examples create a directory named squirrel-data within the specified volume's root or in a directory named tmp within the DBFS root:

Bash
databricks fs mkdir dbfs:/Volumes/main/default/my-volume/squirrel-data
databricks fs mkdir dbfs:/tmp/squirrel-data

databricks fs rm

Removes a directory. Specify the path to the existing directory in DBFS.

If the directory exists but is not empty, an error is returned. If the directory does not exist, nothing happens.

databricks fs rm PATH [flags]

Arguments

PATH

    The path to the existing directory in DBFS

Options

-r, --recursive

    Remove all of the contents

Global flags

Examples

The following examples remove a directory named squirrel-data from the specified volume's root or from a tmp directory in the DBFS root:

Bash
databricks fs rm dbfs:/Volumes/main/default/my-volume/squirrel-data
databricks fs rm dbfs:/tmp/squirrel-data

The following examples remove a non-empty directory named squirrel-data from the specified volume's root or from a tmp directory in the DBFS root:

Bash
databricks fs rm dbfs:/Volumes/main/default/my-volume/squirrel-data -r
databricks fs rm dbfs:/tmp/squirrel-data -r

Global flags

--debug

  Whether to enable debug logging.

-h or --help

    Display help for the Databricks CLI or the related command group or the related command.

--log-file string

    A string representing the file to write output logs to. If this flag is not specified then the default is to write output logs to stderr.

--log-format format

    The log format type, text or json. The default value is text.

--log-level string

    A string representing the log format level. If not specified then the log format level is disabled.

-o, --output type

    The command output type, text or json. The default value is text.

-p, --profile string

    The name of the profile in the ~/.databrickscfg file to use to run the command. If this flag is not specified then if it exists, the profile named DEFAULT is used.

--progress-format format

    The format to display progress logs: default, append, inplace, or json

-t, --target string

    If applicable, the bundle target to use