To delete a folder from the Databricks File System (DBFS), you can use either the Databricks CLI or commands directly from a Databricks notebook.
Here’s how you can do it using both methods:
Using the Databricks CLI
- Install the Databricks CLI: If you haven’t already, install the Databricks CLI on your local machine and configure it using your workspace URL and personal access token.
bash
databricks configure --token
- Delete the Folder: Use the following command to delete a folder. Replace
/path/to/folder
with the actual path of the folder you want to delete.bashdatabricks fs rm -r dbfs:/path/to/folder
This command will prompt you for confirmation before deleting the folder and its contents.
Using Commands from Notebooks
- Open a Notebook: Create a new notebook or open an existing one in your Databricks workspace.
- Run the Command: Use the following command in a notebook cell to delete a folder. Again, replace
/path/to/folder
with the actual path.pythondbutils.fs.rm("/path/to/folder", recurse=True)
Alternatively, you can use the magic command syntax:
python%fs rm -r /path/to/folder
Important Considerations
- Irreversible Action: Once a folder is deleted from DBFS, it cannot be recovered. Ensure that you have appropriate backups if necessary.
- Permissions: Make sure you have the necessary permissions to delete the folder. Only users with write access to the parent directory can delete a subdirectory or its contents.
These methods allow you to manage your DBFS storage effectively, ensuring that you can clean up unnecessary files and directories as needed.