How to download multiple files from Google Drive using terminal

Oleg Khomenko
2 min readApr 28, 2020

--

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

Fig 1. Files we want to download

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) => 'https://drive.google.com/uc?id=' + el.getAttribute('data-id')).join(" ")

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

Fig 2. Links to our files

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 https://drive.google.com/uc?id=1mZ8oKBYrAl04N1cH-tQV1waVfw9u_MEc https://drive.google.com/uc?id=13p4tPPxMJNvjFAY26TJbvtb3XqGnTfqE https://drive.google.com/uc?id=1dH_YWrOMvnxnI0v0m5lkHmGfSra8Bvda https://drive.google.com/uc?id=1Nig2iKteoc-Av-Nc36s6o5c2fdS3LtO7 https://drive.google.com/uc?id=1QPwUY9vWmDMnuey2RK4Ief2u4CHqyRjZ https://drive.google.com/uc?id=1vBMeIK0o_w9LfHPOz7hO4xbO6g_qgQcI; 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 \
https://drive.google.com/uc?id=1mZ8oKBYrAl04N1cH-tQV1waVfw9u_MEc \
https://drive.google.com/uc?id=13p4tPPxMJNvjFAY26TJbvtb3XqGnTfqE \
https://drive.google.com/uc?id=1dH_YWrOMvnxnI0v0m5lkHmGfSra8Bvda \
https://drive.google.com/uc?id=1Nig2iKteoc-Av-Nc36s6o5c2fdS3LtO7 \
https://drive.google.com/uc?id=1QPwUY9vWmDMnuey2RK4Ief2u4CHqyRjZ \
https://drive.google.com/uc?id=1vBMeIK0o_w9LfHPOz7hO4xbO6g_qgQcI; do echo $el; done | xargs -I% -P 5 -n1 gdown %

That’s it, pretty simple.

--

--

Responses (1)