Transferring large files from google drive on command line using gdrive

Downloading large google drive files via gdrive on Mac and Linux seems to be faster than using the wifi connection directly or with something like curl.


On OSX, you can install via homebrew using:

brew install gdrive

On linux, you’ll have to download the custom installation file from github. There seems to be a version for windows but I haven’t tried that.

Establish a connection to your google drive

  • to establish the initial connection, when you first run gdrive an access token is granted through a browser link with a prompt of something like ‘Authentication needed; Go to the following url in your browser:’
  • it seems you may have to reauthenticate the connection every so often because the token will expire. Borrowing from the solution by Stunner in this Github issue, the following works for me to re-establish the connection:
# remove the token file
rm ~/.gdrive/token_v2.json
# run the about subcommand to re-prompt you for authentication:
gdrive about

Download a file or directory

  • you can get a google drive id for each file or directory by right-clicking the file name and selecting ‘get shareable link’. The characters after ‘id =’ is the File ID. It seems the file id will not change if you change permissions or turn off link sharing.
  • For example, the link and corresponding id might be something like:
# Link

  • You can do a simple download with the command ‘gdrive download ' but there are also additional options listed on the github page. For example, add the flag '-r' (recursive) to download a directory recursivey.

Example gdrive first setup

  • This is what the outputs looked like for me during setup of gdrive with some fake urls:
[me@home]$ chmod a+x gdrive-linux-x64
# retrieve file of id 1cMEhUw7qZYlaLGqGMUXhJFxQjYeWzqG corresponding to sequence.fastq
[me@home]$ gdrive-linux-x64 download 1cMEhUw7qZYlaLGqGMUXhJFxQjYeWzqG
Authentication needed
Go to the following url in your browser:[long link here]

Enter verification code: 4bwQA2so5olQhtQLRcm_aEVtOCc0ldAhW
Downloading sequence.fastq -> sequence.fastq
Downloaded 1eq05WGmB--KGMcTPdAwq1Q1x91Tv0F6 at 54.2 MB/s, total 7.1 GB

Written on July 3, 2019