Open In App

Delete a locally Uploaded File on Google Colab

Last Updated : 25 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will learn to delete locally uploaded folders in our Google Colab notebook. You can also refer to the video solution for this end which is attached at the end of this article.

Delete Local Uploaded file on Google Colab

Prerequisite for the task – A Google Account. Refer to this article which explains how to create a Gmail and account, which is equivalent to creating a Google Account.

Upload a zip file of a folder directly on the Colab Notebook

The most simple way to upload a folder onto Google Colab is to create a .zip file of the folder on our local machines and then upload it as a file on Colab. We can create a zip file of the folder and upload it as a file onto Colab using UI.

Step 1: To upload this file, click on “Files” icon on the left-hand side menu bar, and click on the “Upload to session storage” icon. It will open up a local system dialog box. Choose the .zip file and it will get uploaded onto colab session.

Step 2: Use the following command to unzip the file and hence, we get all the required files onto the colab session storage. Now, all the files from the folders can be easily accessed from colab notebook.

!unzip <folder-name>.zip
%ls

Screenshot-2023-09-10-at-13823-AM-(2)

Delete Uploaded Folder from Colab Notebook

There are 2 ways in which this task can be achieved.

Using the Colab Notebook UI

All the files and folders in our session storage can be removed directly from the “Files” section on left-hand side menu. Hover on any file/folder, click on 3 dots and select “Delete” option to delete the file/folder. This way, the file can be easily deleted, but, the folder must be empty in order to be deleted.

Screenshot-2023-09-10-at-31846-AM

Using Command Line

Similarly, the deletions can also be done on command line using the following commands on colab notebook.

rm <file-name>
rmdir <folder-name>

rmdir command can only be used to delete folders which is empty. In order to delete a non-empty folder, use the following command, this will recursively delete everything inside a folder and then the folder in the end.

rm -rf <folder-name>

Screenshot-2023-09-10-at-22940-AM-(1)

By following the above steps, we can easily delete the locally uploaded folders to the colab notebook.

Please refer to the following video, to get a more detailed idea about the process which showcase all the steps mentioned above.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads