2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Google Driveのファイルをlinuxシェルスクリプトでダウンロードする方法

Last updated at Posted at 2022-10-12

Google Driveのファイルをlinuxシェルスクリプトでダウンロードする方法

1. 小さいファイル(100MB未満)の場合

wgetの基本形は、wget "ダウンロードURL" -O "保存ファイル名"なので以下をターミナルで実行

wget "http://drive.google.com/uc?export=view&id=17UjI9766dZFmWRjqngzMjcFyOSMrDXiy" -O "test.txt"

#OR

wget --no-check-certificate "http://drive.google.com/uc?export=view&id=17UjI9766dZFmWRjqngzMjcFyOSMrDXiy" -O "test.txt"

2. 大きいファイル(100MB以上)の場合

以下のようにdownload.shを作成し

FILE_ID="17UjI9766dZFmWRjqngzMjcFyOSMrDXiy";
FILE_NAME="test.txt";
CONFIRM=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate "https://drive.google.com/uc?export=download&id=$FILE_ID" -O- | sed -En 's/.*confirm=([0-9A-Za-z_]+).*/\1/p');
wget --load-cookies /tmp/cookies.txt "https://drive.google.com/uc?export=download&confirm=$CONFIRM&id=$FILE_ID" -O $FILE_NAME;
rm -f /tmp/cookies.txt

以下を実行

chmod 775 download.sh
./download.sh

参考:

https://skume.net/entry/2020/11/23/043738

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?