Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a locally uploaded file on google colab?

I'm trying to delete a file that I uploaded on Google colab using the following code:

from google.colab import files
uploaded = files.upload()

How to delete the file now? e.g If the file's name is 'sample.jpg' .

like image 829
Abhiram Satputé Avatar asked Sep 10 '18 21:09

Abhiram Satputé


People also ask

How do you delete a file from Google Drive in Google Colab?

Open left pane, find the files tab, then right click to select and delete a file.

How do I delete a non empty directory in Colab?

Shutil rmtree() to Delete Non-Empty Directory The rmtree('path') deletes an entire directory tree (including subdirectories under it).

How do I see local files on Google Colab?

2) From a local drive Click on “Choose Files” then select and upload the file. Wait for the file to be 100% uploaded. You should see the name of the file once Colab has uploaded it. Finally, type in the following code to import it into a dataframe (make sure the filename matches the name of the uploaded file).

How do you delete a file in Python?

remove() method in Python can be used to remove files, and the os. rmdir() method can be used to delete an empty folder. The shutil. rmtree() method can be used to delete a folder along with all of its files.


8 Answers

Answer from @Korakot works for a single file and in case, to delete entire folder or subfolders or files

use

!rm -rf <folder_name>

like image 135
Saranraj Nambusubramaniyan Avatar answered Oct 18 '22 00:10

Saranraj Nambusubramaniyan


Try this

!rm sample.jpg

Then check that it is gone with !ls -al

Update (nov 2018) Now you can click to open left pane, browse the files tab, then right click to select and delete a file.

like image 28
korakot Avatar answered Oct 18 '22 00:10

korakot


To delete a folder which has multiple folders, use:

%rm -rf <folder_name>
like image 42
Ankit Chawla Avatar answered Oct 17 '22 23:10

Ankit Chawla


In the menu in Google Collab chose Runtime->Restart all runtimes. This will clear up all your file uploads.

like image 41
Tatyana Lysenko Avatar answered Oct 18 '22 00:10

Tatyana Lysenko


if you are getting edit like,

/bin/bash: -c: line 0: syntax error near unexpected token `newline'

then use

%rm -rf folder_name
like image 21
Vishal Nasre Avatar answered Oct 17 '22 23:10

Vishal Nasre


you can see available data or files through !ls

then use !rm for delete

> from google.colab import files
> 
> !ls
> 
> !rm data.csv

example image

like image 27
Romyull Islam Avatar answered Oct 17 '22 22:10

Romyull Islam


In menu options in Google Colab chose Runtime->Factory reset runtime. This will reset the runtime by deleting all your local file uploads.

like image 27
sai_varshittha Avatar answered Oct 17 '22 23:10

sai_varshittha


use !rm for deleting FILES

  • To remove all files:

          !rm *
    
  • To remove a single file:

          !rm <file_name>
    
like image 35
pablo M Avatar answered Oct 18 '22 00:10

pablo M