Command Line Based Tools for Downloading Files

Sources:

  • Download file from Github with CLI tools
  • Download file from Google Drive with CLI tools

wget

Download the contents of a URL to a file (named "foo" in this case):

1
wget https://example.com/foo

To download a file from github, suppose the URL of the file is

1
https://raw.githubusercontent.com/user/repository/blob/branch/filename

You should remove the /blob and use

1
wget https://raw.githubusercontent.com/user/repository/branch/filename

to download it.

curl

1
curl -O <file>

gdown

Source

To download Google Drive files via CLI, you can use gdown.

  • Only works on open access files. ("Anyone who has a link can View")

Install it with the following command:

1
pip install gdown

After that, you can download any file from Google Drive by running one of these commands:

1
2
3
4
gdown https://drive.google.com/uc?id=<file_id>  # for files
gdown <file_id> # alternative format
gdown --folder https://drive.google.com/drive/folders/<file_id> # for folders
gdown --folder --id <file_id> # this format works for folders too

Example: to download the readme file from this directory

1
gdown https://drive.google.com/uc?id=0B7EVK8r0v71pOXBhSUdJWU1MYUk

The file_id should look something like 0Bz8a_Dbh9QhbNU3SGlFaDg. You can find this ID by right-clicking on the file of interest, and selecting Get link. As of November 2021, this link will be of the form:

1
2
3
4
# Files
https://drive.google.com/file/d/<file_id>/view?usp=sharing
# Folders
https://drive.google.com/drive/folders/<file_id>