Download Files from the Web via the Mac OS X Command Line
I am frequently developing web pages and often times I find it frustrating when I can not restart my browser because I’m in the middle of a download. So when I need to download a large file and I don’t want to have to worry about whether or not Safari, Chrome, or Firefox continues to run with out interruption, I turn to the trusty Terminal! In fact, you can easily download any files from the web by using the command line on a Mac.
The next time you have a file you want to download, just copy the URL into your clipboard, then open a Terminal window and use the ‘curl’ command.
Curl is easy to use for downloading files, at it’s simplest form the syntax would be:
curl -O [filenameURL]
The file destination URL should be prefixed with http for the web. By default this will download the requested URL to the present working directory, using the same name for the saved file as that it was on the remote server (in other words, if the file is called “filename.zip” on the remote server, the name will stay the same when it downloads.
You must use the -O (capital o) flag with curl to get the filename to stay the same. A lowercase -o flag will change the name. curl –help can explain more.
With the basics covered, let’s do something a bit more useful though and specify where the file will save from curl by using a specific example.
First you’ll want to change directories to where to save the file to, this is done with the ‘cd’ command. We’ll use the Desktop as an example:
Now that we have changed our directory to the “Desktop” (for convenience) we can start our download. For the download we are going to use a built in utility called “curl”.
curl -O http://www.exampleURL.com/downloads/Example/DoesNotExist.sit
Curl will instantly download the file. If the file is large enough, you’ll get a progress bar indicating how long it’s taking to download.
You can even combine the above command strings into a single command, if you’d like:
cd ~/Desktop; curl -O http://remote-server-IP/file.zip
Of course, curl has lots of other uses beyond downloading files from the web, so don’t miss our other posts on using curl.
If you have any other helpful tips or tricks for using this method of downloading files from the web, share them with us in the comments below!