Search code examples
linuxubuntucurlterminalubuntu-14.04

Ubuntu: Using curl to download an image


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?


Solution

  • 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