Skip to content

Instantly share code, notes, and snippets.

@vladalive
Created May 16, 2019 14:38
Show Gist options
  • Save vladalive/535cc2aff8a9527f1d9443b036320672 to your computer and use it in GitHub Desktop.
Save vladalive/535cc2aff8a9527f1d9443b036320672 to your computer and use it in GitHub Desktop.
Download Google Drive files from linux terminal via wget

Setup:

  1. Add this code to your ~/.bash_aliases file.
function gdrive_download () {
  CONFIRM=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate "https://docs.google.com/uc?export=download&id=$1" -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')
  wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$CONFIRM&id=$1" -O $2
  rm -rf /tmp/cookies.txt
}
  1. Open new bash session.

Usage:

gdrive_download long_google_drive_file_id filename.ext
@vladalive
Copy link
Author

created this gist from the original one:
https://gist.github.com/iamtekeste/3cdfd0366ebfd2c0d805

@crazyapril
Copy link

Works for me. Thanks!

@AbnerCode
Copy link

why it is not work ?
the error information is the bash command not found

@vladalive
Copy link
Author

@AbnerCode can you please give more details about your error? what's the console output?

@BirkhoffLee
Copy link

Sometimes there's no confirmation needed such as a PDF file.

@SaigyoujiYuyuko233
Copy link

why it is not work ?
the error information is the bash command not found

Did you install wget?

@hundanLi
Copy link

hundanLi commented Mar 1, 2020

I replace "docs.google.com" with "drive.google.com", and it works well for me. Thanks a lot!

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