Unzipping Files Using Terminal 8


Unzipping Files Using Terminal


Terminal, the wonder app, can do pretty much anything. This post is going to show you how you can unzip files using Terminal. I will also show you how you can can combine commands to download and unzip files really quickly. Its really simple to complete. You may want to use Terminal since you can access extra options which you may normally be hidden away from you.

The first step is to open Terminal. Use the “cd” command to change the directory to the location where you want to unzip the zip file. For example you can use:

cd ./Desktop

The next step is to invoke the unzip command. Type the following into Terminal. This assumes you have a zip file ready to unzip.

unzip file.zip

This will unzip you file into you desktop location. If you want to change this location you can type the following.

unzip file.zip -d ~/another/folder

You can also remove all of the text that Terminal will output when you run the command by adding a modifier/option to the front of the syntax.

unzip -q file.zip

Optionally you can also add more information by adding a verbose option. This will show you all of the details of the file you unzip.

unzip -v file.zip

You can combine this command with other command so you can download and unzip a file automatically. For example if you have wget installed you can type in Terminal.

cd ~/download;wget http://www.example.com/file/zip;unzip file.zip

The different commands are separated by a semi-colon (;). The previous command will change your directory to your downloads folder. It will then grab the zip file from your website and unzip the file to your location.

The one problem with unzip command is that it creates a an extra folder called “__MACOSX” this folder would normally be hidden as it stores extra data that you don’t need to see. You can easily get rid of this by combining the delete command with the unzip command.

unzip file.zip;rm -rf __MACOSX

That will unzip the file and then delete this extra folder. You can of course combine this with the download command previously.

cd ~/download;wget http://www.example.com/file/zip;unzip file.zip;rm -rf __MACOSX

You could even take this further by moving files and folders although that would be out of the scope of this article. How quick do you reckon it would be to type that command compared to downloading a zip folder normally and then normally extracting it. You do have to type more, but it is a lot less clicking and searching in Finder.

If you want to take your skills with Terminal a bit further I recommend you check out the Terminal Category on this site. If you fancy reading a book there is a couple on Amazon that I regularly see mentioned and recommend, O’reilly Unix Geeks and Unix Under the Hood both are designed for Mac OS X and take Terminal further.

If you want to keep up with the latests post from Mac Tricks And Tips I recommend you subscribe to the RSS Feed.

Where To Next?

  • Subscribe To Mac Tricks And Tips

8 Responses to “Unzipping Files Using Terminal”

  1. 1

    why bother with this? Safari can already automatically unzip things it downloads? All this does is let you see some extra data about the files you are unzipping.

    Comment By Ian on August 13th, at 3:53 am

  2. 2

    You would only bother with this because it is interesting to use. You expand your use of Terminal. What happens if you are SSH’ing into a server and don’t have access to Safari and only have Terminal access?

    Comment By admin on August 13th, at 10:05 am

  3. 3

    Fair enough, but i have doubts that i will find myself in that situation

    Comment By Ian on August 13th, at 4:16 pm

  4. 4

    I must admit that your blogs is where i keep visiting to learn a lot of terminal tricks, thanks.

    But this unzipping trick is somehow annoying when i tried to do.. say, if unzipping a folder contained nothing but just empty folders with icons set attached to the folders, I’ll get all the weird folders with “__MACOSX”, and the main problem is it breaks all the icons resource into unknown file.

    Comment By Jack on August 18th, at 12:37 pm

  5. 5

    To be perfectly honest this trick isn’t a replacement for your normal unzipping program. It does have some flaws. Regarding your question I don’t know how to solve it. The man page doesn’t say anything explicitly.

    Comment By admin on August 18th, at 3:22 pm

  6. 6

    Hey. Thanks for the info. I needed to send a .zip file to a remote server through SFTP and then used this unzip command in SHH to get my website working. Great info!

    Comment By Justin on August 29th, at 7:57 pm

  7. 7

    You could simply use the command:
    open “your-zipped-file”

    This will do the same thing as if you double-clicked on your zipped file. This will unzip the way you would expect it to.

    Give it a try.

    Comment By Pascal on November 5th, at 2:53 pm

  8. 8


    I have transferred a wordpress installation zip to my webhost and need to unzip the contents of the zip to the root folder of my domain. When I do the unzip command I will get a folder called “wordpress” in the same location as the zip, but I need it to unzip the contents of the folder in the same directory as the zip. How can I do that?

    I tried the unzip -d command, but it preserves the wordpress folder.

    I also tried using the mv command, but again I was only moving the folder around :-/

    Comment By Funkylaundry on July 26th, at 12:12 am