You need to use a tool (command) called curl. It is a tool to transfer data from or to a server, using one of the following supported protocols:
Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | No |
Requirements | curl |
Time | 10m |
- FTP
- HTTP
- HTTPS
- FTPS
- POP3
- SFTP
- SMTPS
- SMTP and more.
macOS Terminal Download File Command
The following command is designed to work without user interaction.
curl command syntax for downloading files on your macOS
The syntax is:
curl 'url' curl [option] 'url' curl -O 'url' curl -L -O 'url' curl -o output.file.name.here 'url-here' curl -o foo.pdf 'http://server1.cyberciti.biz/foo.pdf'
Examples
Open the Terminal and then type the following command to grab “Mastering vim” in pdf format from www.cyberciti.biz server:
curl -o mastering-vim.pdf 'http://www.cyberciti.biz/files/mastering-vi-vim.pdf'
Sample outputs:
curl -O http://www.cyberciti.biz/files/mastering-vi-vim.pdf ls -l *.pdf
How do I specify multiple URLs or parts of URLs?
The syntax is:
# grab files from server1.cyberciti.biz, server2.cyberciti.biz, server3.cyberciti.biz curl -O http://server{1,2,3}.cyberciti.biz/ curl -O http://server{1,2,3}.cyberciti.biz/foo.pdf ## grab latest reports from US, UK, India FTP servers ## curl -O ftp://intranet.site.{us,uk,in}.lic.net.in/reports/latest[a-z].tar.gz
You can get sequences of alphanumeric series by using []. In this example, grab invoices-1.pdf, invoices-2.pdf, …, invoices-1000.pdf using curl command:
curl -O ftp://ftp.cyberciti.biz/invoices-[1-1000].pdf
You can grab urls with leading zeros as follows:
curl -O ftp://ftp.cyberciti.biz/images-[001-300].png
You can combine various techniques to build complex download url structure as follows:
curl -O ftp://ftp.cyberciti.biz/backups-us-[a-z].tar.gz curl -O http://server1.cyberciti.biz/music[1997-2000]/series[1-20]/dump{a,b,c,d,e,f}.tar.gz
You can set a step counter for the ranges to get every Nth number or letter:
## grab http://server1.cyberciti.biz/files/foo1.txt, http://www.cyberciti.biz/files/foo3.txt, http://www.cyberciti.biz/files/foo5.txt ## curl -O http://server1.cyberciti.biz/files/foo[1-10:2].txt ## grab bar-a.pdf, bar-c.pdf, bar-e.pdf, and so on ## curl -O http://server1.cyberciti.biz/files/bar-[a-z:2].pdf
Displaying a progress bar
You can force curl to show progress as a simple progress bar instead of the standard, more informational, meter:
curl -# -O http://www.cyberciti.biz/files/mastering-vi-vim.pdf
Sample outputs:
######################################################################## 100.0%
Dealing with url redirection
The following is recommended syntax for servers that may do http redirect before downloading files. Other servers may hide actual download file names.
curl -L -o 'file.name.here' 'http://example.com/download.php?fileID=foo'
Consider the following filezilla download url from sourceforge foss hosting platform:
## Problems ## # 1. Long ulr name with special characters in it # 2. Url hides actual download file name # 3. Url does http 301 redirect to pick nearest mirror # ----------------------------------------------------- http://downloads.sourceforge.net/project/filezilla/FileZilla_Client/3.7.3/FileZilla_3.7.3_i686-apple-darwin9.app.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2F&ts=1381651492&use_mirror=ncu
To avoid problems, use the following syntax:
## ****************** TIP *************************************** ## ## a) Put all urls in single-quotes to avoid nasty shell surprises ## b) The -L option follows url redirection ## c) The -o 'file' write file to given name ## ****************** TIP *************************************** ## curl -L -o 'filezilla.tar.bz2' 'http://downloads.sourceforge.net/project/filezilla/FileZilla_Client/3.7.3/FileZilla_3.7.3_i686-apple-darwin9.app.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2F&ts=1381651492&use_mirror=ncu'
Sample outputs:
Save bandwidth
You can pass the --compressed option to http based urls to request a compressed response using one of the algorithms curl supports, and save the uncompressed document. If this option is used and the server sends an unsupported encoding, curl will report an error:
curl -L -O --compressed 'http://server1.cyberciti.biz/large.report-tab.html'
Download a file using username and password
The syntax is:
Security alert: Anything (username/password) done over HTTP/FTP is completely open to interception. Do not pass username/passwords using ftp/http protocols.
## Insecure examples ## curl ftp://username:passwd@ftp1.cyberciti.biz:21/path/to/backup.tar.gz curl http://username:passwd@server1.cyberciti.biz/file/path/data.tar.gz ## Secure examples SSL/HTTPS/SFTP etc ## curl --ftp-ssl -u UserName:PassWord ftp://ftp1.cyberciti.biz:21/backups/07/07/2012/mysql.blog.sql.tar.gz ## SFTP example ## curl -u userNameHere sftp://home1.cyberciti.biz/~/docs/resume.pdf
Check out our previous video tutorial on curl command for more information:
Installing wget on macOS to download files
First, install Homebrew on macOS and then type the following brew command:
brew install wget
Now all you have to do is:
wget url
Summing up
You learned how to download file on macOS using terminal commands such as wget and curl.
Recommended readings
- More – Linux / Unix: curl Command Download File Examples
- Linux / Unix: curl Command Pass Host Headers
- See curl command man page for more information.
🐧 5 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
While it is nice to know alternative ways to do tasks without wget on OS X, it is available for OS X.
https://www.macupdate.com/app/mac/33951/wget
If you are already familiar with wget why not install it using mac ports?
Or you could install HomeBrew: http://brew.sh/
Install command: ruby -e “$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)”
And then install wget through it:
Install command: brew install wget
Hey my names Adam,
i would like to know how to download Comand Prompt for mac IOS
Great content!!
I like using also ‘axel’ to download multiple parts from the same file at the same time, increasing the speed :)