DEV Community

Rahul Suryavamshi
Rahul Suryavamshi

Posted on

How to Download a File from Google Drive to a Linux Server using gdown (Python CLI)

What is gdown?

gdown is a Python package that allows you to download files from Google Drive via the command line. It's lightweight, supports resuming downloads, and is great for automation in scripts.


Prerequisites

Before we begin, ensure you have:

  • Python 3.x installed.
  • pip installed (Python package manager).
  • The Google Drive file link you want to download.

Important:
The file must be shared with “Anyone with the link” access.
Private or restricted files cannot be downloaded using gdown unless they are publicly shared.


Install gdown

Install gdown using pip:

pip install gdown
Enter fullscreen mode Exit fullscreen mode

To install it system-wide (if using sudo):

sudo pip install gdown
Enter fullscreen mode Exit fullscreen mode

Or, if you prefer using pip3:

pip3 install gdown
Enter fullscreen mode Exit fullscreen mode

Get the File ID from Google Drive Link

Get the file ID from your Google Drive share link.

Example link:

https://drive.google.com/file/d/1a2b3c4D5eF6G7h8Ij9KLMnoPqRstuV/view?usp=sharing
Enter fullscreen mode Exit fullscreen mode

The file ID here is:

1a2b3c4D5eF6G7h8Ij9KLMnoPqRstuV
Enter fullscreen mode Exit fullscreen mode

Download the File Using gdown

Using the --id Flag

Download the file directly from your terminal:

gdown --id 1a2b3c4D5eF6G7h8Ij9KLMnoPqRstuV -O outputFileName
Enter fullscreen mode Exit fullscreen mode

Replace outputFileName with the desired name for your downloaded file.

This command will fetch the file from Google Drive

Top comments (0)