How to Download Large Google Drive Files using the Command Line

Hussain AminuHussain Aminu
2 min read

Google Drive is a popular cloud storage service that allows users to store and share files. Sometimes, you may need to download a large file from Google Drive using the command line, especially if the file is too large to download via a web browser. In this article, we'll walk through the steps of downloading a large Google Drive file using the command line.

Step 1: Get the file ID

The first step in downloading a file from Google Drive using the command line is to get the file ID. To do this, follow these steps:

  1. Go to your Google Drive in your browser.

  2. Right-click (or control-click) the file you want to download and click "Get shareable link".

  3. The link will look something like this: https://drive.google.com/open?id=XXXXX. Make note of the file ID "XXXXX"; you will be needing it below.

Step 2: Get an OAuth Token

Next, you need to get an OAuth token. To do this, follow these steps:

  1. Go to OAuth 2.0 Playground.

  2. In the "Select the Scope" box, scroll down, expand "Drive API v3", and select https://www.googleapis.com/auth/drive.readonly.

  3. Click "Authorize APIs" and then "Exchange authorization code for tokens". Copy the "Access token"; you will be needing it below.

Step 3: Download the File from the Command Line

Once you have the file ID and the OAuth token, you can download the file from the command line. To do this, follow these steps:

  1. If using OS X or Linux, open the "Terminal" program and enter the following command:

    curl -H "Authorization: Bearer YYYYY" https://www.googleapis.com/drive/v3/files/XXXXX?alt=media -o ZZZZZ

  2. If using Windows, open the "PowerShell" program and enter the following command:

    Invoke-RestMethod -Uri https://www.googleapis.com/drive/v3/files/XXXXX?alt=media -Method Get -Headers @{"Authorization"="Bearer YYYYY"} -OutFile ZZZZZ

  3. Replace "XXXXX" with the file ID from Step 1, "YYYYY" with the access token from Step 2, and "ZZZZZ" with the file name that will be saved (e.g., "myFile.mp4" if you're downloading an mp4 file).

  4. Press Enter and let the download begin.

Conclusion

Downloading a large Google Drive file using the command line is a straightforward process. By following the above steps, you can easily download a file from Google Drive using the command line. This can be particularly useful when dealing with large files that are too cumbersome to download via a web browser.

0
Subscribe to my newsletter

Read articles from Hussain Aminu directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Hussain Aminu
Hussain Aminu

Experienced web developer with a background in ICT management and software development. Skilled in team management and collaboration, with a proven track record of delivering high-quality code.