Last active
June 4, 2019 02:29
-
-
Save josherich/9ffa514359d9cbd089a445e70141fa06 to your computer and use it in GitHub Desktop.
How to download file from Google Drive using command line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add function to .bashrc(or .zshrc) | |
google_drive_dl() { | |
echo "input file id: " | |
read file_id | |
echo "input file name: " | |
read file_name | |
curl -c ./cookie -s -L "https://drive.google.com/uc?export=download&id=${file_id}" > /dev/null | |
curl -Lb ./cookie "https://drive.google.com/uc?export=download&confirm=`awk '/download/ {print $NF}' ./cookie`&id=${file_id}" -o $file_name | |
} | |
# or use as a script google_drive_dl.sh | |
#!/bin/bash | |
# file id for the google drive file | |
file_id="file_id" | |
file_name="file.zip" | |
# 1. save cookie | |
curl -c ./cookie -s -L "https://drive.google.com/uc?export=download&id=${file_id}" > /dev/null | |
# 2. use confirm field in cookie to download file | |
curl -Lb ./cookie "https://drive.google.com/uc?export=download&confirm=`awk '/download/ {print $NF}' ./cookie`&id=${file_id}" -o $file_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment