Abhiram Satputé
Abhiram Satputé

Reputation: 604

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' .

Upvotes: 37

Views: 138744

Answers (12)

Snehal Rajput
Snehal Rajput

Reputation: 436

If you want to delete any specific type of file, such as a pdf( can be replaced with .txt, .png, .jpeg etc !rm -rf /path_of_folder/*.pdf

Upvotes: 0

hamza
hamza

Reputation: 21

With this command, You can delete any folder in Colab !rm -rf ./folder_name

Upvotes: 0

Mainland
Mainland

Reputation: 4594

Go to run time and select delete runtime. This clears all the temporary variables and downloaded data. You can start fresh

Before clicking:

enter image description here

After clicking:

enter image description here

Upvotes: 0

pablo M
pablo M

Reputation: 531

use !rm for deleting FILES

  • To remove all files:

          !rm *
    
  • To remove a single file:

          !rm <file_name>
    

Upvotes: 2

Vishal Nasre
Vishal Nasre

Reputation: 41

if you are getting edit like,

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

then use

%rm -rf folder_name

Upvotes: 4

Akankhya Mohapatra
Akankhya Mohapatra

Reputation: 51

Terminating the sessions under Manage my sessions option is perhaps the easiest way one can do it. There could be downsides of losing other files which you may not want to get rid of and will have to upload them again!

Sometimes, factory reset runtime either after termination of session or without it works as well! Try the combinations and you will find the secret to deleting locally uploaded file (:-D)

Note - If only terminating session does not work, sometimes reloading the webpage again ensures that all locally uploaded files are deleted and you can re-run with freshly uploaded files :)

Upvotes: 0

sai_varshittha
sai_varshittha

Reputation: 323

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

Upvotes: 2

Ankit Chawla
Ankit Chawla

Reputation: 111

To delete a folder which has multiple folders, use:

%rm -rf <folder_name>

Upvotes: 11

Romyull Islam
Romyull Islam

Reputation: 41

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

Upvotes: 3

korakot
korakot

Reputation: 40928

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.

Upvotes: 35

Tatyana Lysenko
Tatyana Lysenko

Reputation: 51

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

Upvotes: 5

Saran
Saran

Reputation: 1844

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

use

!rm -rf <folder_name>

Upvotes: 62

Related Questions