[Linux](EN) Download file or resource using curl command

Download resources(files or web pages) by using curl command.


Environment and Prerequisite

  • Linux base system
  • Bash shell(/bin/bash)
  • Usage of curl command


About curl command

  • curl : It stands for Client URL. It is a tool to transfer data from or to a server, using one of the supported protocols
  • The command is designed to work without user interaction. It supports many protocols and methods also with many options.
  • Supported Protocols : DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET, TFTP and ETC.


Download resource using curl command

(Method 1) Use -o or –output option

  • These options only support download to current working directory.
curl [URL] -o [RESOURCE_NAME]

or

curl [URL] --output [RESOURCE_NAME]


(Method 2) Use redirection

  • You can download resource to any directory.
curl [URL] > [RESOURCE_NAME_WITH_PATH]


Example : Download cirros image using curl command

Requirements


(Method 1) Use -o or –output option

  • Download file
curl https://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img -o cirros-0.4.0-x86_64-disk.img
  • Check MD5 hash value
  • MD5 hash value could be different depends on OS.
$ md5sum cirros-0.4.0-x86_64-disk.img
443b7623e27ecf03dc9e01ee93f67afe  cirros-0.4.0-x86_64-disk.img


(Method 2) Use redirection

  • Download file
curl https://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img > /home/twpower/test/cirros-0.4.0-x86_64-disk.img
  • Check MD5 hash value
  • MD5 hash value could be different depends on OS.
$ md5sum /home/twpower/test/cirros-0.4.0-x86_64-disk.img
443b7623e27ecf03dc9e01ee93f67afe


Reference

[Linux] 쉘 스크립트에서 멀티프로세스(혹은 스레드) 기능 사용하기

> 백그라운드로 명령어를 실행해서 병렬적으로 실행되는 멀티 프로세스 환경을 만들어보자.## 환경- Linux 기반 시스템- Bash shell(/bin/bash)## 멀티프로세스? 병렬처리? 멀티스레드? 백그라운드 프로세스?- 여기서 진행할 방식...… Continue reading