If you work with any type of computer on a regular basis, you have probably used a zip file at one time or another. These files are extremely useful when it comes to packaging, compressing, and transferring files from one place to another, but how do you unzip them in Mac Terminal?
If you’re working from the desktop, Mac’s Archive Utility can easily open these files with just a couple of clicks, but in Mac Terminal, you need to open them from the command line by typing in a specific command.
My name is Eric and I have worked as a software engineer for nearly 25 years. I specialize in deploying software to development, test, and production environments, so I use zip files on a daily basis, and doing this in a Mac terminal is nothing new to me.
This is a fairly simple process and if you would like to learn how to do it, stick around and keep reading below. I will show you the straightforward command as well as some other variations of it. We can also take a quick look at the background of zip and see why it is used so much.
Contents
The Command to Unzip Files on Mac Terminal
Simply unzipping a file on Mac Terminal is very fast and easy. While there are variations, other parameters, and many ways you can unzip, if you are just trying to extract the files into the directory where the zip file exists, there’s not a lot to it.
All you need to do is open a Mac Terminal window, navigate to the location of the zip and run the unzip command as shown below.
unzip <filename>
Where <filename> denotes the name of your particular file. You don’t even have to include the .zip extension (but you can). Not a lot to it, right? Keep in mind that running the command this way, will expand all the files contained in the zip to your current directory.
This can sometimes be a mess if it contains many files and/or folders. So you may want to preview what is in the file first before doing this. I will touch on this a bit further in this article.
One thing you can do to alleviate the problem of all the files going into your current folder is to specify a destination folder to which you want to have all the files extracted. This can be done by using the -d parameter along with the name of the directory you want to extract to.
unzip <filename> -d <directory>
One of the great features of this command is that if the directory does not already exist, it will create it for you. No need to create it beforehand.
Now that you have seen the command, look at a couple of examples.
Example 1: Unzip <filename>
For the first one, we’ll just run unzip <filename>.
Step 1: Below is the directory with only the zip file I wish to extract. Notice there are no other files in the directory.
Step 2: Below I have run the command unzip ziptest. You can see the output showing that the command is extracting the files from the zip file.
Step 3: Now when I look at the directory, I can see that all the files have been extracted into my current directory. This could be a bit confusing or cause issues if I need to keep these newly extracted files separated from other files in this directory.
Example 2: Unzip using -d parameter
Now I will run the unzip command using the -d parameter so that it creates a folder to extract all of the files in.
Step 1: For this example, I have cleared the directory and once again have only the zip file there.
Step 2: Now I will run the command using the -d parameter (unzip ziptest -d myzips) to specify that I want it to put the files in a directory called myzips. Notice in the output that you can see it is extracting it to the myzips directory.
Now in the current directory, you will see only the original zip file and the newly created myzips directory.
Let’s take a look inside the myzips directory.
I moved into the myzips directory using the cd command and as you can see it contains the files that were extracted.
Other Parameters to Unzip Files via Mac Terminal
The -d parameter which lets you specify a directory to extract the files into, is not the only available parameter for the unzip command. There are many others. Some of them are very technical such as the -X parameter which lets you restore the original UID/GID of each file.
Other parameters such as -o instruct the command to overwrite any existing files without prompting you to verify. One that I find most useful is the -l parameter. It allows you to take a look at what is in the zip before extracting everything. You simply type the command below.
unzip <filename> -l
The output shows you the contents of the file so that you know beforehand what is in it. From there you can decide where to extract the files and even extract only the specific files you want if you choose to do so. Below I have shown the output using the file from our examples above.
As you can see it provides a nice listing of the files inside and even shows their size. I find that I use this command a lot. I normally run it before extracting any zip file in which I do not know the contents beforehand so that I know what I am extracting.
There are lots of other parameters. You can see them by simply typing the unzip command and hitting enter.
If you want to see more details of the unzip command and full explanations of each parameter you can use the man command to see the man page. Type the command below.
man unzip
You will get an output similar to the one shown below.
You can hit enter to move through the document line by line or hit the space key to advance to the next page. You will see that there are pages and pages of information. When you are done looking at it just hit q to exit the man page.
As you can see there are many options and parameters that you can use with the unzip command. Take some time to play around and experiment with the command and its options to see what you can do with it.
What is a Zip File?
If you are trying to extract a zip file in Mac Terminal, then you probably know what a zip file is, but if you are new to zip files, no worries. I will give you a brief overview of them here. Once you get familiar with them and how they work, you will be amazed by their usefulness.
Zip files are nothing new, they have been around since the late 1980s. I remember using them quite frequently because back then our hard drives and other media such as floppy disks, didn’t have a whole lot of space to store files, and zip files made this easier.
This is because the zip command which creates zip files, can take one or multiple files, compress them and package them into one single zip file. The resulting zip file is much smaller than the original file or files which saves space and makes it much easier to transport.
Instead of copying or sending multiple large files from one place to another and trying to store all of them, you now have only one file to deal with that is much smaller in size and easier to handle. When you need the files inside, you simply unzip them and they are ready to go.
Zip files can be used on almost any computer platform or operating system. They may seem a bit like magic but there is a lot of technology behind them. Take a look at this article if you would like to learn more about the details of how they work.
Final Words
If you are looking to unzip files on Mac Terminal, you will find that the process is fast and not at all difficult. Although there are many options and parameters that can be used with the command, you can learn what they are by typing the command alone or looking at the man page.
Let me know how the unzip command works for you. As always, I would love to hear from you!