Download Files from the Web via the OS X Command Line

May 11, 2007 - 9 Comments

Terminal in OS X 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!

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:
cd ~/Desktop

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
.
Curl in action

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: Bill Ellis in Command Line, Mac OS X, Tips & Tricks

9 Comments

» Comments RSS Feed

  1. Dan Shockley says:

    You might want to include a few extra bits in that post. First, always include the -L (or –location) switch, since that will allow curl to follow any redirects (if the file gets moved, but there is a redirect for it). Also, if the URL’s file part (the section after the last slash) is not pretty, you can give a name for the downloaded file by using a lower-case -o (instead of -O), followed by a space and the name in quotes. Also, always put the URL in single-quotes – ampersands and a few other characters will break on the command line if they aren’t in quotes. Here’s an example of those ideas combined:

    curl -L -o ‘myfile.dmg’ ‘http://www.somewebsite.com/files/getdmg?id=24′

  2. boomer says:

    I have never used the curl command but this is pretty good

  3. ToBeFrank says:

    I use wget

  4. Chris says:

    nice, this really helped me tonight

  5. Bill says:

    I also use wget. you have to download it and compile it. or install it using fink or macports.

  6. ton350d says:

    Thanks, for your share.I’m happy to use Terminal download ISO file :)

  7. Download says:

    Is there an addon or a command I can use to download all files from a directory or a page ?

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates