Nerd For Tech
Published in

Nerd For Tech

Connecting Your Google Colab and Google Drive

Photo by Toa Heftiba on Unsplash

Connecting google drive and google colab is simple but necessary knowledge. But sometimes we can’t figure it out how to do this. Let’s start by opening new notebooks in your google colab.

After that you need to put this function from google colab in order to connect with your drive

Next, you need to mount the drive within your colab environment. It will ask you to open new link like this

Just open the link and copies the verification code

Paste the verification code into the box inside the google colab, and then press enter

If you verification is success, the output will be like this

So whenever you type !ls in the notebook, you will got new directory named drive.

Also if you want using the GUI mode, just press the directory in left panel, you will got the drive that you mount before


FYI, I think google colab is Linux based system, so you can type any command of Linux there. In my case I want to go inside the dataset directory inside my drive. To access it via notebook you should using % than ! because the function is different. The ! is temporary, but the % will be persistent. Here is the example

If you are the type person who don’t believe with CLI command, you can check it the GUI version about what inside this directory ‘/content/drive/MyDrive/dataset’

Well, right now if you wan to extract zip file you can using command like this

!unzip '{ZIP Files}' -d '/new_directory/{ZIP Files}'

Just try it out and see what will you get!!!

Thanks for reading


  • The mounting point is absolutely yours, but many person using common directory like ‘/content/drive’, it’s good to make it same with people, because whenever you work as team, your team will not confused.
  • The verification code actually change everytime, so you don’t need to feel worried about sharing the code. I just like to make it like that, to make it as a habit.
  • The ‘%’ command is very useful to move around directory, it can give you more clean code actually
  • The command ‘-d’ in unzip is used to extract the data inside new directory without create it



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store