Delete all the cells of the Databricks Notebook

3.2k Views Asked by At

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

2

There are 2 best solutions below

2
On BEST ANSWER

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.

0
On

After I went through @AlexOtt answer I tried that using the UI and it worked.

If you want to delete all the cells in a notebook then first you need to click on the select all cells option in the context menu. this would select all the cells that are present in the notebook and now if you select the option of delete cells then it would delete all the cells.

This was confusing as the option was showing text as delete cells and deleting only the cell that had the cursor but now I know how I can do it, UI options makes sense but could have been more user friendly.