94

I want to download an image accessible from this link: https://www.python.org/static/apple-touch-icon-144x144-precomposed.png into my local system. Now, I'm aware that the curl command can be used to download remote files through the terminal. So, I entered the following in my terminal in order to download the image into my local system:

curl https://www.python.org/static/apple-touch-icon-144x144-precomposed.png

However, this doesn't seem to work, so obviously there is some other way to download images from the Internet using curl. What is the correct way to download images using this command?

Manas Chaturvedi
  • 5,210
  • 18
  • 52
  • 104

6 Answers6

173

curl without any options will perform a GET request. It will simply return the data from the URI specified. Not retrieve the file itself to your local machine.

When you do,

$ curl https://www.python.org/static/apple-touch-icon-144x144-precomposed.png

You will receive binary data:

                   |�>�$! <R�HP@T*�Pm�Z��jU֖��ZP+UAUQ@�
��{X\� K���>0c�yF[i�}4�!�V̧�H_�)nO#�;I��vg^_ ��-Hm$$N0.
���%Y[�L�U3�_^9��P�T�0'u8�l�4 ...

In order to save this, you can use:

$ curl https://www.python.org/static/apple-touch-icon-144x144-precomposed.png > image.png

to store that raw image data inside of a file.

An easier way though, is just to use wget.

$ wget https://www.python.org/static/apple-touch-icon-144x144-precomposed.png
$ ls
.
..
apple-touch-icon-144x144-precomposed.png
ddavison
  • 28,221
  • 15
  • 85
  • 110
  • when download images from `google drive` they won't open as usual. But the code (`curl `) you have given works well, is it a google security measure or is there any other way? – Kasun Siyambalapitiya Nov 18 '16 at 08:08
  • 1
    what if I want to save the actual binary data to a file instead of getting the image? – Fabian Rios Nov 20 '18 at 13:14
  • 2
    @FabianRios, I guess it's as simple as to change the extension of the format to .txt instead of .png, I just tried and it worked. – Amit Amola May 31 '21 at 08:36
63

For those who don't have nor want to install wget, curl -O (capital "o", not a zero) will do the same thing as wget. E.g. my old netbook doesn't have wget, and is a 2.68 MB install that I don't need.

curl -O https://www.python.org/static/apple-touch-icon-144x144-precomposed.png
rath3r
  • 323
  • 1
  • 6
  • 19
jwh
  • 731
  • 5
  • 2
29

If you want to keep the original name — use uppercase -O

curl -O https://www.python.org/static/apple-touch-icon-144x144-precomposed.png

If you want to save remote file with a different name — use lowercase -o

curl -o myPic.png https://www.python.org/static/apple-touch-icon-144x144-precomposed.png

daGo
  • 2,584
  • 26
  • 24
9

Create a new file called files.txt and paste the URLs one per line. Then run the following command.

xargs -n 1 curl -O < files.txt

source: https://www.abeautifulsite.net/downloading-a-list-of-urls-automatically

korchix
  • 1,445
  • 1
  • 19
  • 22
5

For ones who got permission denied for saving operation, here is the command that worked for me:

$ curl https://www.python.org/static/apple-touch-icon-144x144-precomposed.png --output py.png
George G
  • 7,443
  • 12
  • 45
  • 59
2

try this

$ curl https://www.python.org/static/apple-touch-icon-144x144-precomposed.png > precomposed.png

  • 2
    Refer stack overflow guidelines on how you post an answer, mainly how is this answer different from the others posted before you and also formatting your answer will help. – briantaurostack7 Jun 13 '21 at 01:54
  • It is shorter and much clear. Downvoting is misleading because it makes the impression that the answer is wrong, but it isn't. – Ivailo Bardarov Jul 29 '21 at 07:39