Reputation: 604
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
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
Reputation: 21
With this command, You can delete any folder in Colab !rm -rf ./folder_name
Upvotes: 0
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:
After clicking:
Upvotes: 0
Reputation: 531
use !rm for deleting FILES
To remove all files:
!rm *
To remove a single file:
!rm <file_name>
Upvotes: 2
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
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
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
Reputation: 111
To delete a folder which has multiple folders, use:
%rm -rf <folder_name>
Upvotes: 11
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
Upvotes: 3
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
Reputation: 51
In the menu in Google Collab chose Runtime->Restart all runtimes. This will clear up all your file uploads.
Upvotes: 5
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