Published on

How to partially download a file

Authors

Ever came across a big file that you wanted to check out but didn't want to download the entire file? Or maybe you wanted to download a file but your internet connection was too slow? Or maybe you wanted to download a file but you didn't have enough space on your hard drive? Here's a quick solution to such problems.

# Download the first 10,000 bytes of the file:
wget --header='Range: bytes=0-10000' -O - https://storage.googleapis.com/gresearch/kelm-corpus/updated-2021/quadruples-train.tsv
# You can change the range to download any part of the file
# For example, to download the last 5,000 bytes of the file, you can use the following command:
wget --header='Range: bytes=-5000' -O - https://storage.googleapis.com/gresearch/kelm-corpus/updated-2021/quadruples-train.tsv
# Lastly, if you want to download the first 10 lines of the file (instead of bytes), you can use the following command:
wget -O - https://storage.googleapis.com/gresearch/kelm-corpus/updated-2021/quadruples-train.tsv | head -n 10

Alternatively, you may use curl instead of wget:

curl -r 0-10000 https://storage.googleapis.com/gresearch/kelm-corpus/updated-2021/quadruples-train.tsv | head -n 10

Note that it's not guaranteed that the server will support partial downloads. If the server doesn't support partial downloads, you might get errors like this:

# wget: server returned error: HTTP/1.1 416 Requested Range Not Satisfiable
# curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume.

Thanks for reading!

Feel free to reach to me on Twitter or LinkedIn if you have any questions or suggestions.