How to download files from Google Drive using Linux Terminal
Google Drive is Google’s cloud storage service used by many people to store their data. If you use Google Drive on Windows or Linux Desktop, you can download files from Google Drive to your computer using a browser. But what if you use Linux Server, only command line interface? I tried wget command to download google drive but it didn’t work. on Python, there is a tool called gdown that helps you download Download Google Drive using Terminal.
1. What is Gdown? Use Gdown to download Google Drive files
gdown is written on python, so on Linux or Windows with Python installed, you will be able to use this tool. With many gdown parameters to help you easily download files from Google Drive with a single command line. This tool helps you to download large files from Google Drive using the command line interface. If you’ve ever tried curl or wget failed because of Google’s security features, try using Gdown.
-Install Gdown
Before installing Gdown you need to install PIP first
-
For CentOS/Rhel
# yum -y install python-pip
-
For Ubuntu/Debian
# apt install python3-pip
After installing PIP, install Gdown with the following command
# pip install gdown
-How to use Gdown
To download files with Gdown, the first thing you need to do is get the public link of the file to download(direct download link)
- Example link: https://drive.google.com/u/0/uc?id=1R1Xl2Xa3CNu_CViM2Pv8UjhfY9WTyhVN&export=download
After determining the link. You use the following command to download
- Syntax:
gdown link_public
gdown https://drive.google.com/u/0/uc?id=1R1Xl2Xa3CNu_CViM2Pv8UjhfY9WTyhVN&export=download
2. Use WGET to download Google Drive files
The second way that I want to share is to use wget with a few parameters to load.
- Example link: https://drive.google.com/u/0/uc?id=1R1Xl2Xa3CNu_CViM2Pv8UjhfY9WTyhVN&export=download
You notice the paragraph 1R1Xl2Xa3CNu_CViM2Pv8UjhfY9WTyhVN is the ID of the file saved on Google Drive. You need to copy and get this ID segment
Finally, now you can download the file through the wget command only, depending on how large or small the file is, you have a different command structure:
- For small files:
# wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=FILEID' -O FILENAME
- For large files:
# wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=FILEID' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=FILEID" -O FILENAME && rm -rf /tmp/cookies.txt
Where FILEID is the ID of the file above and FILENAME is the name of the file you want to save on your computer.
- Note: The download command on large files can be applied to small files as well. But the command with small files is not applicable to large files
You will have a result like the image below (click on the image to see the original image in more detail):
Good luck!