Here is an answer that has worked for me for large files as of August 10, 2023. The source is from this website. In order to use this command, you must make sure that your file is available to anyone on the internet.
Merely run 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
Here, FILEID
is the ID from the download URL (right-click file >> Share >> Copy link), and FILENAME
is the name of the file. It will download the file (even if it's large) to the folder that you run the script with the name of the file as the name of the downloaded file.
If you'd like this as a Bash script (written by GPT-4, but it's tested and works), you can save this as download.sh
, make it runnable with chmod +x download.sh
, and then run it with ./download.sh
.
#!/bin/bash
# Ask for file id
echo "Please enter the file id:"
read FILEID
# Ask for filename
echo "Please enter the filename:"
read FILENAME
# Run the wget command
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
In addition, here's a (GPT-4-generated) breakdown of each portion of the command:
1. `wget`: This is a free utility for non-interactive download of files from the web. It supports HTTP, HTTPS, and FTP protocols, as well as retrieval through HTTP proxies.
2. `--load-cookies /tmp/cookies.txt`: This option tells wget to load cookies from the file `/tmp/cookies.txt`.
3. `"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"`: This is the URL to download the file from. It includes a sub-command that uses wget to fetch a confirmation token needed for the download.
4. `--quiet`: This option tells wget to work quietly, i.e., without displaying any output.
5. `--save-cookies /tmp/cookies.txt`: This option tells wget to save cookies to the file `/tmp/cookies.txt`.
6. `--keep-session-cookies`: This option tells wget to keep session cookies. These are cookies that are deleted when the browser is closed.
7. `--no-check-certificate`: This option tells wget not to check the server certificate against the available certificate authorities.
8. `-O-`: This option tells wget to write the documents to standard output.
9. `| sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p'`: This part uses the sed command to extract the confirmation token from the output of the previous wget command.
10. `-O $FILENAME`: This option tells wget to write the downloaded file to a file named `$FILENAME`.
11. `&& rm -rf /tmp/cookies.txt`: This part of the command deletes the `/tmp/cookies.txt` file if the previous commands were successful. The `&&` operator only runs the command to its right if the command to its left was successful. The `rm -rf /tmp/cookies.txt` command removes the file `/tmp/cookies.txt`.