Search code examples
databricksspark-notebook

Delete all the cells of the Databricks Notebook


I am working on Databricks notebook for some of the spark work that I am doing. I am using notebook just as a proof of concept work initially and then organized that so that I can create jar out of it. As I am doing POC I try adding lot of cells to experiment different ways. Over a period of time the notebook has large number of cells and most of the stuffs is not required as I have organized that and move to a finalized notebook/Jar code. I am deleting the cells one by one but that can be time consuming. So I just wanted to know if there is a way to delete all the cells from the notebook at one.

There is one option at the top of the notebook that says delete cells but when I click on that it just deletes the single cell and not all the cells from the notebook.

Snapshot of the top UI where I see option of delete cells is as below :

enter image description here


Solution

  • When you work with Databricks notebooks, you can work in the two modes, similar to the VI editor:

    1. Edit mode, when you edit the code of the individual cells
    2. Command mode - in this case, you're working not with the code, but with the cells, so you can select several cells at once, cut/copy/paste/delete them, etc. (see documentation or click on the Shortcuts in the ? item of UI).

    From the documentation you will see that in the command mode (press ESC to enter into it) you can select all cells, or you can use Shift + cursor to select several cells, and then you can press d two times, and this will trigger deletion of the selected cells.