Sub topic 12
DBFS Paths, /dbfs and FileStore
This chapter assumes you can run Python and SQL in a Databricks notebook and know what a Unity Catalog volume is. Its goal is to help you recognize the DBFS path styles in older code and to know which ones still deserve a place in new code.
Three ways to write the same DBFS location
DBFS is the Databricks File System, a layer over the workspace's root cloud storage. The same file can be addressed in three ways, depending on which API is reading it.
| Style | Example | Used by |
|---|---|---|
| URI with scheme | `dbfs:/FileStore/data/sales.csv` | Spark, `dbutils.fs`, the Databricks CLI |
| Absolute path with no scheme | `/FileStore/data/sales.csv` | Spark and `dbutils.fs`, which assume DBFS |
| Local file path | `/dbfs/FileStore/data/sales.csv` | Code that uses the local file system, such as `open()` and pandas |
Spark and dbutils.fs resolve a path with no scheme as DBFS. The /dbfs prefix is different. It is a FUSE mount, which makes DBFS look like a local directory, so tools that know nothing about Databricks can read it.
# Same file, three spellings
spark_path = "dbfs:/FileStore/data/sales.csv"
local_path = "/dbfs/FileStore/data/sales.csv"
df = spark.read.csv(spark_path, header=True)
with open(local_path) as f:
print(f.readline())What FileStore is
/FileStore is a folder in the DBFS root. Older notebooks and tutorials used it for uploaded files, for plots, and for files that a browser could download. Files saved under /FileStore were once served at a URL of the form https://<workspace-host>/files/.... Some workspaces now restrict or disable this behavior. Treat it as a feature that may be switched off.
display(dbutils.fs.ls("dbfs:/FileStore/"))Several other DBFS root folders appear in old code, such as /tmp and /user/hive/warehouse. The DBFS root is readable and writable by every user in the workspace, and Unity Catalog does not govern it.
Why this matters for new work
Files in the DBFS root have no per-file privileges. Anyone with workspace access can usually read them. Volumes address this problem with READ VOLUME and WRITE VOLUME. For that reason, Databricks recommends volumes for non-tabular data. In some workspaces, such as those with serverless compute or certain access modes, DBFS root and mount access is limited or unavailable. Code that uses /dbfs may then fail.
Reading old code
When you see a path in a notebook, check its prefix before you decide what it does.
dbfs:/...or a bare/FileStore/...means a DBFS path used through Spark ordbutils./dbfs/...means local file access to DBFS./Volumes/...means a Unity Catalog volume. This is the path style to use for new code.
The volume equivalent of a DBFS listing replaces only the path:
# Legacy pattern: DBFS root path
display(dbutils.fs.ls("dbfs:/FileStore/"))
# Preferred pattern: Unity Catalog volume path
display(dbutils.fs.ls("/Volumes/main/default/landing/"))Exercise
A notebook runs pd.read_csv("dbfs:/FileStore/data/sales.csv") and fails, while spark.read.csv("dbfs:/FileStore/data/sales.csv") works. Why, and what path would make the pandas call work?
Show answer
pandas uses the local file system, which does not understand the dbfs: scheme. Use the FUSE mount path /dbfs/FileStore/data/sales.csv. For new code, move the file to a volume and read /Volumes/<catalog>/<schema>/<volume>/sales.csv with both tools.
Exercise
Which of these paths is a local-file view of DBFS: dbfs:/tmp/a.txt, /tmp/a.txt, or /dbfs/tmp/a.txt?
Show answer
/dbfs/tmp/a.txt. The dbfs: form is the URI and the bare /tmp/a.txt is resolved as DBFS by Spark and dbutils, but is a driver-local path for open().