Advertisement

Monday man page: curl


Today's man page covers one of my favorite utilities: curl. No, it's not a haircare product -- it's one of the most flexible download tools in the kit bag, with the ability to handle almost any protocol that can be addressed via a URL (hence the name, short for "client for URLs"). If there's a server out there that's reachable via HTTP, HTTPS, FTP, SFTP, SCP, and lots of other alphabet soup, curl can talk to it.

curl http://www.tuaw.com/2007/03/05/monday-man-page-curl/ -- display the source of this very article in Terminal
curl ftp://ftp.panic.com -- list the contents of a remote FTP site, in this case one with a pretty good FTP client
curl -o ~/Desktop/curl-man.html http://curl.haxx.se/docs/manpage.html -- copy the curl manpage to your desktop; if you use capital -O, the local file mirrors the remote filename

curl has an excellent usage manual at its site, detailing examples of use and advanced techniques. While there are zillions of ways to use curl in site testing, analysis and uploading, my favorite way of using it is as a quick file downloader. Read on for the details.


curl does an awesome job of quickly and cleanly downloading files, making it perfect for DIY software distribution schemes. In my case, I keep a web-shared folder of current installers and packages zipped up for delivery, and then when I'm managing a remote user's machine, I can trigger the downloads via ssh and curl -- all behind the user's back:

curl http://myserver.example.com/Installer.mpkg.zip -o /tmp/install.zip
unzip -o install.zip
sudo installer -pkg /tmp/Installer.mpkg -target /


If you wanted to do something really cool, though, you could take advantage of curl's ability to compare file timestamps, and trigger a download only when the source file is updated -- great for a login script:

curl -z updater.zip http://server.example.com/updater.zip

thereby making sure that the client always has the latest file downloaded. So handy!

Hannes adds a comment below that he always uses the -C option to allow curl to resume interrupted file downloads, a trick that Safari hasn't mastered yet:

curl -C -O http://example.com/bigfile.zip

One last fun trick: using curl to do dictionary lookups...

curl dict://dict.org/d:macintosh
20 aspen.miranda.org dictd 1.9.15/rf on Linux 2.6.18-3-k7 <7204009.9729.1173071849@aspen.miranda.org>
250 ok
150 2 definitions retrieved
151 "Macintosh" gcide "The Collaborative International Dictionary of English v.0.48"
Mac \Mac\ prop. n.
Shortened form of {Macintosh}, a brand name for a personal
computer; as, the latest Mac has great new features.
[PJC]
.
151 "Macintosh" gcide "The Collaborative International Dictionary of English v.0.48"
Macintosh \Mac"in*tosh\, n.
1. Same as {Mackintosh}.
[1913 Webster]

2. [Trademark.] (Computers) A brand of personal computer
featuring an integrated system in which the hardware and
system-operating software were designed by or under the
control of a single company, the Apple Computer
Corporation; among personal computers, distinguished from
the {IBM-compatible} or {Intel-based} series of computers.
[PJC]