64

I want to download a folder from my google drive using terminal? Is there any way to do that? I tried this:

$ wget "https://drive.google.com/folderview?id=0B-Zc9K0k9q-WWUlqMXAyTG40MjA&usp=sharing"

But it is downloading this text file: folderview?id=0B-Zc9K0k9q-WdEY5a1BCUDBaejQ&usp=sharing. Is there any way to download google drive folder from terminal?

  • 2
    Check Mount Google Drive in Linux?. – henrique Jun 10 '14 at 12:11
  • I have checked them but they can't handle google spreadsheet. As I need access to spreadsheet and ocamlfuse can handle this, I thought of downloading them everytime I need them though time comsuming with respect to mount. But I have no other options. – user22180 Jun 10 '14 at 12:36
  • Set the folder setting to "anyone on the internet can find and view", then you will be able to download the file with wget https://googledrive.com/host/file_id for you that is wget https://googledrive.com/host/0B-Zc9K0k9q-WdEY5a1BCUDBaejQ. Solution explained here in more details. – Paul Rougieux May 11 '16 at 12:30
  • Any new answers for this during the time passed? we have one option below. – Matan Jan 21 '18 at 19:23
50

I was able to download a public shared file using this command:

$ wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=FILEID' -O FILENAME

Where FILEID must be replaced by the actual file ID. FILENAME is the path/filename where download will be stored.

Note you cannot use a folderid instead of fileid. I have used view source in a folder view where I could find the following HTML <div id="entry-0B0jxxycBojSwVW.... The string starting with 0B was the fileid.

| improve this answer | |
  • 6
    This worked great for me! just had to use drive.google.com instead – thouliha Jun 11 '15 at 14:36
  • since I had a large file I kept getting the google virus scanner warning (that it can't scan). I did not find a solution for this problem. However, I realized that I could simply use scp to transfer the file to my server (which had the need for such downloading) – Matthias Sep 9 '16 at 16:56
  • 2
    this is not working anymore with google drive... – loretoparisi Apr 10 '17 at 0:00
  • 2
    This won't work for larger files. This answer in stack overflow works like a charm : stackoverflow.com/a/32742700/4773609 – H G Sur May 4 '17 at 7:42
  • 1
    @HGSur My answer below also works for large files. – Goodbye StackExchange Jun 25 '18 at 21:09
11

A newer, open-source multi-platform client, written in Go called drive is quite nice and full-featured, and also is in active development.

Examples

The pull command downloads data from Google Drive that does not exist locally, and deletes local data that is not present on Google Drive. Run it without any arguments to pull all of the files from the current path:

$ drive pull

Pulling by matches is also supported

$ cd ~/myDrive/content/2015
$ drive pull --matches vines docx

See the above link for further examples, these are just the tip of the iceberg.

| improve this answer | |
  • 1
    This tool is not maintained since September 2017 – reducing activity Nov 1 '18 at 11:30
  • 1
    Yes but it still works and to download a whole directory it's the best solution: drive pull 'Colab Notebooks/sorted/models/resnet-101-90.9-max-acc'. The other methods are a pain in the ass. – Avio Aug 9 '19 at 9:49
9

There is a giant program in the ubuntu 17.04 repository called: rclone

$ sudo apt update && sudo apt install rclone

$ rclone config --> than follow the steps to setup your gdrive

now you can rclone copy and sync everything you want. The projects supports all kinds of clouds.. f.e.:

$ rclone sync /home/<usrname>/Desktop/yourfolder gdrivename:yourfolder

[1]: https://rclone.org

(btw I uploaded about 600GB and transferred 1TB with rclone from gdrive to gdrive in few hours, gdrive to ubuntu and ubuntu to gdrive.. and it works terrific over weeks in a row!!

https://forum.rclone.org/t/can-copy-between-google-drive-accounts-without-download-and-upload-files/969/8

)

| improve this answer | |
  • Documentation is lacking. Following the steps one by one doesn't work. – Jivan Feb 25 at 14:50
  • Be careful about the order in rclone sync a b. I created a test dir and did rclone sync testdir drive:/important_folder and it attempted to delete all the files in drive:/important_folder. Fortunately, I had only given drive.readonly access to my drive. Reversing the order of arguments works. – Mehdi Saffar Apr 20 at 17:02
8

you can try, if you are on firefox, installing cliget addon. For every file that you want to download program show you curl, wget or aria2 direct link for downloading that file. I use that to download files on other machines via ssh because it's much faster for me to download directly to remote computer then to upload that file from my computer. This also work with dropbox, gdrive etc.

| improve this answer | |
  • This is by far the best answer! Thank you! – Philipp Schwarz Apr 19 at 13:41
7

wget can only handle direct links, but that is not the main problem here. Google Drive expects you to authenticate before downloading your file. This means you will have to use a web browser to download the file. There are a few web browsers for the terminal, lynx is an example.

If you choose to publicly share your file (so that anyone can download it) you can use one of the numerous Google Drive permalink services. I believe these should produce links that will work with wget. Here is a list of two I found when searching for information: http://gdriveurl.com/ http://gdurl.com/

Assuming you are running Linux there is an open source client for Google Drive that might be worth looking into.

| improve this answer | |
  • lynx is showing "redirecting" for more than 5 minutes when trying to access the drive. "Google Drive permalink" is ok, but I don't want to share it with everyone. I have used Grive and Ocamlfuse but they can't access spreadsheets – user22180 Jun 10 '14 at 10:37
  • Confirmed the "download" link from gdriveurl worked with wget – Randall Mar 24 '16 at 21:38
  • regarding the open source client suggestion: from my experience using that gdrive client and a similar utility called rclone, I have had better experiences with rclone. – 7yl4r Jun 23 '17 at 17:10
6

You can use the open source Linux / Unix command line tool gdrive.

To install it:

  1. Download the binary. Choose the one that fits your architecture, for example gdrive-linux-x64.

  2. Copy it to your path.

    sudo cp gdrive-linux-x64 /usr/local/bin/gdrive;
    sudo chmod a+x /usr/local/bin/gdrive;
    

To use it:

  1. Determine the Google Drive folder's ID. For that, go inside the folder to download, using the drive.google.com web client. Now look at the URL in the browser's address bar, it will show something like https://drive.google.com/drive/folders/0B7_OwkDsUIgFWXA1B2FPQfV5S8H. Obtain the string behind the last / and copy it to your clipboard. That's the folder's ID.

  2. Download the folder. Of course, use your folder's ID instead in the following command.

    gdrive download --recursive 0B7_OwkDsUIgFWXA1B2FPQfV5S8H
    

At first usage, the tool will need to obtain access permissions to the Google Drive API. For that, it will show you a link which you have to visit in a browser, and then you will get a verification code to copy&paste back to the tool. The download then starts automatically. There is no progress indicator, but you can observe the progress in a file manager or second terminal.

Source: A comment by Tobi in a stackoverflow.com question. Answer adapted from my similar answer over there.

| improve this answer | |
  • 3
    Can't get permission? Sign in with Google temporarily disabled for this app This app has not been verified yet by Google in order to use Google Sign In. – unami Dec 7 '19 at 23:49
  • Same here: "Sign in with Google temporarily disabled for this app" – Jivan Feb 25 at 14:53
4

Download binary from the below link

chmod +x <binary>
./drive download id

It will generate link for verification code. Click the link and allow access to gdrive and copy the verification code from browser. Paste it.

It works for me

| improve this answer | |
0

2 useful Python programs (require: sudo apt install -y python3 python3-pip):

  • gdown: Download a large file public from Google Drive (curl/wget fails due to security notice)
    • pip install gdown
  • gshell: Navigate in Google Drive as you do on shell (gshell = Google Drive + Shell).

Examples:

To download 1 public large file from Google Drive (5 GB):

# syntax: gdown https://drive.google.com/uc?id=FILE-ID
gdown https://drive.google.com/uc?id=1LC5iVcvgksQhNVJ-CbMigqXnPAaquiA2

To download 1 folder:

gshell init              # log in to your Google account 
gshell ll                # list files
gshell download spam.txt # download file -> you could script to download all files listed by gshell ll

I use gdown and it works well. I haven't tried gshell.

Note that if one uses gdown more than ~20 times within 24 hours, we get the error:

Access denied with the following error:

    Too many users have viewed or downloaded this file recently. Please
    try accessing the file again later. If the file you are trying to
    access is particularly large or is shared with many people, it may
    take up to 24 hours to be able to view or download the file. If you
    still can't access a file after 24 hours, contact your domain
    administrator.

You may still be able to access the file from the browser:

    https://drive.google.com/uc?id=1LC5iVcvgksQhNVJ-CbMigqXnPAaquiA2
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.