95

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?

slm
  • 369,824
user22180
  • 1,123

8 Answers8

59

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.

wimh
  • 691
  • 7
    This worked great for me! just had to use drive.google.com instead – dessalines 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 09 '16 at 16:56
  • 3
    this is not working anymore with google drive... – loretoparisi Apr 10 '17 at 00:00
  • 2
    This won't work for larger files. This answer in stack overflow works like a charm : http://stackoverflow.com/a/32742700/4773609 – H G Sur May 04 '17 at 07:42
  • 1
    @HGSur My answer below also works for large files. – Blue Jun 25 '18 at 21:09
  • I am currently not able to verify this, but vasiliki suggested the following: The way to find the file's unique ID is to right click on the file and click Get Shareable Link option. There you must turn it on and then from the link, the part after id= is your file ID. – wimh Jun 26 '19 at 18:23
  • 2
    It doest not work for folders! – Miguel Sep 13 '19 at 12:31
  • Hello, does this work also for password protected folders with username? – stephanmg Jan 10 '20 at 13:24
  • 1
    do you have a solution for entire folders in gdrive? – Charlie Parker Apr 23 '21 at 20:24
  • 2
    I honestly wonder what people think when they just keep upvoting unrelated answer. OP is asking for a folder not a file – Farid Jul 18 '22 at 07:34
22

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). pip install gshell (maybe discontinued)

To upload to GDrive, one can use https://labbots.github.io/google-drive-upload/.


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 (might depend on the file size), 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
  • 2
    this worked like an absolute charm, thank you! this was quick an easy and IMO should definitely be more of an accepted answer. i guess maybe the handicap is having to install python, instead of a more direct native CLI program (but your instructions are directly copy & pastable) – greenhouse Jun 23 '20 at 02:34
  • 1
    Amazing! Thank you very much! – monsune Oct 23 '20 at 17:28
  • gshell unfortunately redirects to https://accounts.google.com/signin/oauth/danger, which tells me that the app has been temporarily disabled – BedirYilmaz Nov 26 '20 at 06:04
  • gdown does not continue to download if the download operation is crashed – alper Dec 13 '20 at 23:05
  • 1
    this is the easiest way to download and should have a lot more upvotes – noob Mama Jan 06 '21 at 06:09
  • 1
    gshell works perfectly even for shared link, all you have to do open link on the browser and select Add shortcut to Drive and the file will be available on your account files list – Salem F Jul 23 '22 at 15:54
14

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.

Utgarda
  • 241
  • 2
  • 6
  • 5
    This tool is not maintained since September 2017 – reducing activity Nov 01 '18 at 11:30
  • 2
    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 09 '19 at 09:49
  • 2
    gdrive is the current up-to-date solution, also written in Go, even easier than the above one https://github.com/prasmussen/gdrive For instance, to download a folder you do gdrive download --recursive FOLDER_ID_FROM_URL, no config necessary, it will ask for your credentials. – rfabbri Jun 16 '21 at 00:20
  • I had a lot of trouble with this tool - it works as advertised, but the definitions they use take some time to get used to. Note that copy means copying inside the drive - not to your local machine, and download is pull. I blew up my Google Drive trying to "copy" files to my local machine and was surprised to never get any local files. – Guss Oct 27 '21 at 06:42
14

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

)

III
  • 141
  • Documentation is lacking. Following the steps one by one doesn't work. – Jivan Feb 25 '20 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 indrive:/important_folder. Fortunately, I had only given drive.readonly access to my drive. Reversing the order of arguments works. – Mehdi Saffar Apr 20 '20 at 17:02
  • 1
    The setup is quite complex, but documentation is much better now. I also recommend using rclone-browser as a (mostly) graphical UI to rclone and makes using it much easier (it does not help with configuration though - you should still expect to need to read a lot of stuff and follow complex directions). You should probably allocate at least half an hour to setting this up, unless you have a lot of experience setting up GCP projects. – Guss Oct 27 '21 at 06:33
  • Unfortunately I have too low rep to add another answer about rclone, but this actually works -- look at answers here: https://unix.stackexchange.com/questions/37234/mount-google-drive-in-linux It took me ~20 mins to go through enabling Google Drive API access, rclone config (you need to paste the client ID and secret there), then rclone ls gdrive: (gdrive: is the name you give to the remote you create in rclone config). – Tomasz Gandor Nov 03 '21 at 18:54
10

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.

tanius
  • 874
  • 5
    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. – ucb Dec 07 '19 at 23:49
  • 2
    Same here: "Sign in with Google temporarily disabled for this app" – Jivan Feb 25 '20 at 14:53
9

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.

lazar
  • 91
8

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.

arnefm
  • 3,172
  • 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
2

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

GAD3R
  • 66,769
Aspire
  • 153