반응형
Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

테크매니아

Google Drive file download in CLI terminal 본문

카테고리 없음

Google Drive file download in CLI terminal

SciomageLAB 2024. 10. 20. 16:33
반응형

CLI 터미널 환경에서 구글 드라이브 대용량 파일을 다운 받아야 하는 경우가 생긴다.

하지만 Google Drive URL은 파일 그 자체가 아니라 웹 브라우저로 연결된다.

파일을 Host PC에 다운 받아서 옮기기에는 시간이 오래 걸리고 wget 같은 걸로는 바로 다운로드가 안된다.

아래 쉘 스크립트는 구글 드라이브 링크를 파라미터로 넣으면 다운로드 해 주는 스크립트이다.

브라우저로 보는 링크로 들어가서 쿠키를 받고 파일까지 받아준다.

if [ $# -eq 0 ]
then
    echo Enter drive url, eg) https://drive.google.com/u/0/uc?id=xxxxxxxxxx
else
    FILE_ID=$(echo $1 | awk -Fid= '{ print $2 } ' | awk -F& '{ print $1 } ')
    echo FILE ID : $FILE_ID

    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 FILDNAME
fi

아래처럼 쓰거나, 적절히 스크립트를 저장해 놓고 alias을 연결해서 쓰면 좋다.

$ ./get-google-drive.sh https://drive.google.com/u/0/uc?id=aaaaaaaaaaaaaaaaa

참고 : https://gldmg.tistory.com/144

반응형