共用方式為


DBFS CLI (舊版)

重要

此檔已淘汰,且可能未更新。

此資訊適用于舊版 Databricks CLI 0.18 版和更新版本。 Databricks 建議您改用較新的 Databricks CLI 0.205 版或更新版本。 請參閱 什麼是 Databricks CLI? 。 若要尋找 Databricks CLI 的版本,請執行 databricks -v

若要從 Databricks CLI 0.18 版或更新版本移轉至 Databricks CLI 0.205 版或更新版本,請參閱 Databricks CLI 移轉

您可以執行 Databricks DBFS CLI 子命令,將它們附加至 databricks fs (或別名 dbfs ),前面會加上 dbfs:/ 所有 DBFS 路徑。 這些子命令會呼叫 DBFS API

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

  Utility to interact with DBFS. DBFS paths are all prefixed
  with dbfs:/. Local paths can be absolute or local.

Options:
  -v, --version
  -h, --help     Show this message and exit.

Commands:
  cat        Shows the contents of a file. Does not work for directories.
  configure
  cp         Copies files to and from DBFS.
    Options:
      -r, --recursive
      --overwrite     Overwrites files that exist already.
  ls         Lists files in DBFS.
    Options:
      --absolute      Displays absolute paths.
      -l              Displays full information including size and file type.
  mkdirs     Makes directories in DBFS.
  mv         Moves a file between two DBFS paths.
  rm         Removes files from DBFS.
    Options:
      -r, --recursive

對於列出、移動或刪除超過 10k 個檔案的作業,我們強烈建議您使用 DBFS CLI。

  • 作業 listdatabricks fs ls ) 將在大約 60 多歲之後逾時。
  • 作業 movedatabricks fs mv ) 會在大約 60 多歲之後逾時,可能會導致部分移動的資料。
  • 作業 deletedatabricks fs rm ) 會以累加方式刪除檔案批次。

建議您使用 檔案系統公用程式 (dbutils.fs) 在叢集的內容中執行這類作業。 dbutils.fs 涵蓋 DBFS REST API 的功能範圍,但涵蓋筆記本的功能範圍。 使用筆記本執行這類作業可提供更佳的控制,例如選擇性刪除、管理性,以及自動執行定期作業的可能性。

限制

不支援使用 Databricks DBFS CLI 搭配已啟用防火牆的儲存體容器。 Databricks 建議您使用 Databricks 連線 az storage

列出檔案的內容

若要顯示使用方式檔,請執行 databricks fs cat --help

databricks fs cat dbfs:/tmp/my-file.txt
Apache Spark is awesome!

複製檔案

若要顯示使用方式檔,請執行 databricks fs cp --help

databricks fs cp dbfs:/tmp/your_file.txt dbfs:/parent/child/grandchild/my_file.txt --overwrite

成功時,此命令不會顯示任何內容。

列出檔案和目錄的相關資訊

若要顯示使用方式檔,請執行 databricks fs ls --help

databricks fs ls dbfs:/tmp --absolute -l
file  42408084  dbfs:/tmp/LoanStats.csv    1590005159000
file        40  dbfs:/tmp/file_b.txt       1603991038000
dir          0  dbfs:/tmp/hive                         0
dir          0  dbfs:/tmp/mlflow                       0
file       385  dbfs:/tmp/multi-line.json  1597770632000
dir          0  dbfs:/tmp/new                          0
dir          0  dbfs:/tmp/parent                       0
file       243  dbfs:/tmp/test.json        1597770628000
file        40  dbfs:/tmp/test_dbfs.txt    1603989162000

建立目錄

若要顯示使用方式檔,請執行 databricks fs mkdirs --help

databricks fs mkdirs dbfs:/tmp/new-dir

成功時,此命令不會顯示任何內容。

移動檔案

若要顯示使用方式檔,請執行 databricks fs mv --help

databricks fs mv dbfs:/tmp/my-file.txt dbfs:/parent/child/grandchild/my-file.txt

成功時,此命令不會顯示任何內容。

刪除檔案

若要顯示使用方式檔,請執行 databricks fs rm --help

databricks fs rm dbfs:/tmp/parent/child/grandchild/my-file.txt
Delete finished successfully.