6

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
  • 3
    curl $URL -o outfile works for me... – jasonwryan Sep 8 '15 at 22:31
5

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.

1

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
-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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.