Skip to content

Instantly share code, notes, and snippets.

@ricardodeazambuja
Forked from isphus1973/dgoogle_download.sh
Last active February 16, 2020 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricardodeazambuja/415cf5776d370eedf09df779778ceb0e to your computer and use it in GitHub Desktop.
Save ricardodeazambuja/415cf5776d370eedf09df779778ceb0e to your computer and use it in GitHub Desktop.
How to download stuff directly from google drive into a jupyter notebook / colab
#!/bin/sh
######Usage#######
# ./dgoogle_download.sh FILE_ID OUTPUT_NAME
## Remember to chomod +x dgoogle_download.sh
#This scrip is based on https://unix.stackexchange.com/questions/136371/how-to-download-a-folder-from-google-drive-using-terminal
LINK="https://drive.google.com/uc?export=download&id="$1
CODE="$(wget -q --save-cookies $1.txt --keep-session-cookies --no-check-certificate $LINK -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1/p' )"
LINK="https://drive.google.com/uc?export=download&confirm=$CODE&id="$1
wget --load-cookies cookies.txt $LINK -O $2
rm -f $1.txt
@ricardodeazambuja
Copy link
Author

One-liner version (using -q, therefore no outputs from wget) to be used with Jupyter notebooks:
!FILENAME="<name_used_to_save_your_file>" && ID="<id_copied_from_link>" && LINK="https://drive.google.com/uc?export=download&id="$ID && CODE="$(wget -q --save-cookies $ID.txt --keep-session-cookies --no-check-certificate $LINK -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1/p' )" && LINK="https://drive.google.com/uc?export=download&confirm=$CODE&id="$ID && wget -q --load-cookies $ID.txt $LINK -O $FILENAME && rm -f $ID.txt && echo $FILENAME '...done!'

@ricardodeazambuja
Copy link
Author

Extra notes:
Follow these steps and it is possible to open the shared link on incognito mode and press the ESC key as soon as you click on the download button. Then, you just need to add the address between quotation marks because bash gets confused with the & character: $ curl -L -o local_file_name 'link_to_google_drive_file_copied'

  • If the file is too large, you will need to copy the link from "Download Anyway" button instead and follow instructions here.
  • Another option seems to be rclone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment