Changing directory in Google colab (breaking out of the python interpreter)

willwade picture willwade · Jan 17, 2018 · Viewed 112.7k times · Source

So I'm trying to git clone and cd into that directory using Google collab - but I cant cd into it. What am I doing wrong?

!rm -rf SwitchFrequencyAnalysis && git clone https://github.com/ACECentre/SwitchFrequencyAnalysis.git

!cd SwitchFrequencyAnalysis

!ls datalab/ SwitchFrequencyAnalysis/

You would expect it to output the directory contents of SwitchFrequencyAnalysis - but instead its the root. I'm feeling I'm missing something obvious - Is it something to do with being within the python interpreter? (where is the documentation??)

Demo here.

Answer

Fabian Linzberger picture Fabian Linzberger · Jan 25, 2018

use

%cd SwitchFrequencyAnalysis

to change the current working directory for the notebook environment (and not just the subshell that runs your ! command).

you can confirm it worked with the pwd command like this:

!pwd

further information about jupyter / ipython magics: http://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-cd