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?

5
  • 2
    Check Mount Google Drive in Linux?.
    – henrique
    Commented Jun 10, 2014 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
    Commented Jun 10, 2014 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. Commented May 11, 2016 at 12:30
  • Any new answers for this during the time passed? we have one option below.
    – matanox
    Commented Jan 21, 2018 at 19:23
  • this also seems like a very useful and related link: stackoverflow.com/questions/25010369/… Commented Apr 23, 2021 at 20:28

8 Answers 8

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.

10
  • 7
    This worked great for me! just had to use drive.google.com instead
    – dessalines
    Commented Jun 11, 2015 at 14:36
  • 3
    this is not working anymore with google drive... Commented Apr 10, 2017 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
    Commented May 4, 2017 at 7:42
  • 2
    It doest not work for folders!
    – Miguel
    Commented Sep 13, 2019 at 12:31
  • 2
    I honestly wonder what people think when they just keep upvoting unrelated answer. OP is asking for a folder not a file
    – Farid
    Commented Jul 18, 2022 at 7: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
6
  • 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
    Commented Jun 23, 2020 at 2:34
  • 1
    Amazing! Thank you very much!
    – monsune
    Commented Oct 23, 2020 at 17:28
  • gshell unfortunately redirects to accounts.google.com/signin/oauth/danger, which tells me that the app has been temporarily disabled Commented Nov 26, 2020 at 6:04
  • 1
    this is the easiest way to download and should have a lot more upvotes
    – noob Mama
    Commented Jan 6, 2021 at 6: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
    Commented Jul 23, 2022 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.

4
  • 5
    This tool is not maintained since September 2017 Commented Nov 1, 2018 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
    Commented Aug 9, 2019 at 9:49
  • 2
    gdrive is the current up-to-date solution, also written in Go, even easier than the above one 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
    Commented Jun 16, 2021 at 0: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
    Commented Oct 27, 2021 at 6: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

)

4
  • Documentation is lacking. Following the steps one by one doesn't work.
    – Jivan
    Commented Feb 25, 2020 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. Commented Apr 20, 2020 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
    Commented Oct 27, 2021 at 6:33
  • Unfortunately I have too low rep to add another answer about rclone, but this actually works -- look at answers here: unix.stackexchange.com/questions/37234/… 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). Commented Nov 3, 2021 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.

2
  • 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
    Commented Dec 7, 2019 at 23:49
  • 2
    Same here: "Sign in with Google temporarily disabled for this app"
    – Jivan
    Commented Feb 25, 2020 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.

2
  • This is by far the best answer! Thank you! Commented Apr 19, 2020 at 13:41
  • This is not even an answer. OP wants it via terminal not manually
    – Farid
    Commented Jul 18, 2022 at 5:53
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.

3
  • 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
    Commented Jun 10, 2014 at 10:37
  • Confirmed the "download" link from gdriveurl worked with wget
    – Randall
    Commented Mar 24, 2016 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
    Commented Jun 23, 2017 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

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .