Databricks File System - DBFS

Databricks File System (DBFS) is a distributed file system installed on Databricks Runtime clusters.

DBFS is a layer over Azure Blob storage and is available in both Python and Scala. Files in DBFS persist to Azure Blob storage, so you won’t lose data even after you terminate a cluster.

In a Spark cluster you access DBFS using Databricks Utilities. On your local computer you access DBFS using the CLI.

Access DBFS with the CLI

The DBFS command-line interface leverages the DBFS API to expose an easy to use command-line interface to DBFS. Using this client, interacting with DBFS is as easy as running:

# List files in DBFS
dbfs ls
# Put local file ./apple.txt to dbfs:/apple.txt
dbfs cp ./apple.txt dbfs:/apple.txt
# Get dbfs:/apple.txt and save to local file ./apple.txt
dbfs cp dbfs:/apple.txt ./apple.txt
# Recursively put local dir ./banana to dbfs:/banana
dbfs cp -r ./banana dbfs:/banana

For more information about the DBFS command-line interface, see Databricks CLI.

Access DBFS with dbutils

This section has several examples of how to write files to and read files from DBFS using dbutils.


To access the help menu for DBFS, use the command.

  • Write file to and read files from DBFS as if it were a local filesystem.

    dbutils.fs.put("/foobar/baz.txt", "Hello, World!")
  • Use dbfs:/ to access a DBFS path.

  • Use file:/ to access the local disk."file:/foobar")
  • Filesystem cells provide a shorthand for accessing the dbutils filesystem module. Most dbutils.fs commands are available using the %fs magic command as well.

    %fs rm -r foobar

For more information about Databricks Utilities, see Databricks Utilities.

Access DBFS using the Spark API

sc.parallelize(range(0, 100)).saveAsTextFile("/tmp/foo.txt")
sc.parallelize(0 until 100).saveAsTextFile("/tmp/bar.txt")

Access DBFS using local file APIs

You can use local file APIs to read and write to DBFS paths. Azure Databricks configures each node with a fuse mount that allows processes to read and write to the underlying distributed storage layer.

# write a file to DBFS using python i/o apis
with open("/dbfs/tmp/test_dbfs.txt", 'w') as f:
  f.write("Apache Spark is awesome!\n")
  f.write("End of example!")

# read the file
with open("/dbfs/tmp/test_dbfs.txt", "r") as f_read:
  for line in f_read:
    print line
// scala

val filename = "/dbfs/tmp/test_dbfs.txt"
for (line <- Source.fromFile(filename).getLines()) {


  • Local file I/O APIs only support files less than 2GB in size. You might see corrupted files if you use local file I/O APIs to read or write files larger than 2GB. Access it using the DBFS CLI, use dbutils.fs, or use Hadoop Filesystem APIs to access large files instead.

  • If you write a file using the local file I/O APIs and then immediately try to access it using the DBFS CLI, dbutils.fs, or the Hadoop Filesystem APIs, you might encounter a FileNotFoundException, a file of size 0, or stale file contents. That is expected because the OS caches writes by default. To force those writes to be flushed to persistent storage (in our case DBFS), use the standard Unix system call sync.

    // scala
    import scala.sys.process._
    // Write a file using the local file I/O API (over the fuse mount).
    dbutils.fs.put("file:/dbfs/tmp/test", "test-contents")
    // Unless you call this, the code below might not see the file or its latest contents.
    "sync /dbfs/tmp/test" !
    // Read the file using "dbfs:/" instead of the fuse mount.

Mount Azure Blob storage and Azure Data Lake stores

Mounting Azure Blob storage and Data Lake stores directly to DBFS allows you to access files as if they were on the local file system.

For information on how to mount and unmount Azure Blob storage and Azure Data Lake stores, see Mount Azure Blob storage containers with DBFS and Mount Azure Data Lake Store with DBFS.