How to download multiple files from Google Drive using terminal

Sometimes it may be quite annoying to download files from Google Drive folders one by one. To make this task easier one may use terminal and special console tool — gdown

Let’s find out how to download weights available for PyTorch model via shared link (Fig 1.)

First, you need to install gdown: pip install gdown

Second, open the shared folder via link using your favorite browser and go to developer tools (Unix: ctrl+shift+I, macOS: command+option+I) ▶ console. To obtain the links, type down the following command into your console:

$$("[data-id]").map((el) => '' + el.getAttribute('data-id')).join(" ")

You will see ready-to-use URLs for gdown CLI (Fig 2.)

Finally, open your terminal and use the following command to download all files (don’t forget to replace %LINKS% with string and remove quotation marks):

for f in %LINKS%; do gdown $f; done# e.g.
# for f in; do gdown $f; done

Moreover, you can use xargs to parallelize and speed up downloading. Just replace gdown $f with echo $f and redirect output to xargs :

for f in %LINKS%; do echo $f; done | xargs -I% -P 5 -n1 gdown %
# e.g.
# for el in \ \ \ \ \ \; do echo $el; done | xargs -I% -P 5 -n1 gdown %

That’s it, pretty simple.

Deep Learning Engineer @ Samsung AI Center, Moscow

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