13

For example, there is a file here that I want to download via CLI: https://raw.githubusercontent.com/raspberrypi/linux/rpi-4.1.y/arch/arm/configs/bcmrpi_defconfig

How to I download the actual file, and not the html?

I tried the following, but only get an html file:

[pi@raspberrypi]/usr/src/linux$ wget https://raw.githubusercontent.com/raspberrypi/linux/rpi-3.2.27/arch/arm/configs/bcmrpi_defconfig
1
  • 4
    curl $URL -o outfile works for me...
    – jasonwryan
    Sep 8, 2015 at 22:31

5 Answers 5

19

The general problem is that github typically serves up an html page that includes the file specified along with context and operations you can perform on it, not the raw file specified. Tools like wget and curl will just save what they're given by the web server, so you need to find a way to ask the web server, github, to send you a raw file rather than an html wrapper. This is true whether you use -o -O or >>. The "...//raw.git..." address in this particular test case is probably serving raw files, and pre-solving the OP's problem as posted, which is why all of these answers work, but don't solve the more generic problem. I can download a text file, or an html-wrapped version of it from the following urls. Note the differences between them and feel free to paste them in a new tab or new window in your browser as well.

html-wrapped, default:

https://github.com/raspberrypi/linux/blob/rpi-4.9.y/arch/arm/configs/bcmrpi_defconfig

raw link, if you right-click the [raw] button on the html page:

https://github.com/raspberrypi/linux/raw/rpi-4.9.y/arch/arm/configs/bcmrpi_defconfig

final url, after being redirected:

https://raw.githubusercontent.com/raspberrypi/linux/rpi-4.9.y/arch/arm/configs/bcmrpi_defconfig

You can then download with either:

wget https://raw.githubusercontent.com/raspberrypi/linux/rpi-4.9.y/arch/arm/configs/bcmrpi_defconfig
curl https://raw.githubusercontent.com/raspberrypi/linux/rpi-4.9.y/arch/arm/configs/bcmrpi_defconfig -o bcmrpi_defconfig

The simplest way would be to go to the github page of the content you want and right-click to get the [raw] link for each file. If your needs are more complex, requiring many files, etc. you may want to abandon wget and curl and just use git. It is probably a more appropriate tool for pulling data from git repositories.

2

It looks like there is a certificate problem, ie:

certificate common name 'www.github.com' doesn't match requested host name 'raw.githubusercontent.com'

If you trust the actors involved, then you can ignore this by adding the wget argument: --no-check-certificate.

2

Download and save the file using wget -O myfile.extension url e,g:

wget -O myfile.txt https://raw.githubusercontent.com/raspberrypi/linux/rpi-3.2.27/arch/arm/configs/bcmrpi_defconfig
2
  • Watch out for the -O option. It must be UPPERCASE, -o does not work.
    – AlienKevin
    Jan 28, 2020 at 0:18
  • @AlienKevin -o is used to create a log file.
    – GAD3R
    Jan 28, 2020 at 9:21
2

Looks like the original "raw" link works now. Just click "raw" to get the downloadable link.

https://gist.githubusercontent.com/...
1

Or try:

wget https://raw.githubusercontent.com/raspberrypi/linux/rpi-3.2.27/arch/arm/configs/bcmrpi_defconfig >> textdownloaded.txt

It puts the content into a file.

I hope it works as well for you.

1
  • did you mean to have the wget command in there, perhaps with an option to save the file directly?
    – Jeff Schaller
    Mar 30, 2016 at 18:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .