Unzip files in particular directory or folder under Linux or UNIX

by on May 29, 2007 · 13 comments· LAST UPDATED May 29, 2007

in , ,

Q. I’m new to Linux command line. I’ve a command called unzip and a file called package.zip. I can extract file using command:
unzip package.zip

All files are extracted into current directory (it is making a directory called package). I want all files and subdirectory extracted into /opt directory. How do I extract files in /opt?

A. unzip command will list, test, or extract files from a ZIP archive, commonly found on MS-DOS systems. The default behavior (with no options) is to extract into the current
directory (and subdirectories below it) all files from the specified ZIP archive.

By default, all files and subdirectories are recreated in the current directory; the -d option allows extraction in an arbitrary directory (always assuming one has permission to write to the directory). This option need not appear at the end of the command line; it is also accepted before the zipfile specification (with the normal options), immediately after the zipfile specification, or between the file(s) and the -x option. The option and directory may be concatenated without any white space between them, but note that this may cause normal shell behavior to be suppressed.

unzip {.zip-file-name}-d {/path/to/extract}

For example extract package.zip into /opt, enter:
# unzip package.zip -d /opt
# cd /opt
# ls

If you want to rename package directory use mv command:
# mv package newname

Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 13 comments… read them below or add one }

1 AD February 27, 2009 at 1:19 pm


1. How do you add a date to the unzipped folder name, or indeed its contents?
2. How do you delete the oldest zip files found inside a folder?
3. How do you move zip files to a backup folder once extraction has been complete?
4. How do you verify that the contents of the zip file have not been corrupted?
5. How do you run MySQL commands from a bash script, such as to load a csv file from the contents of a zip file into MySQL table?



2 suren July 13, 2009 at 1:46 pm

how to gzip all the files undre one dictory?
For example:
i have a dir /home/suren/dir
in this i have files
from /home/suren/ i want to execute a command to gzip all files under dir.


3 Zhiping June 13, 2010 at 11:32 am

tar -zcvf dir.tar.gz dir


4 SANJAY TEJANI December 16, 2010 at 9:36 am



5 savitha A February 21, 2012 at 11:46 am

tar -xzf dir.tar.gz


6 charles pere August 9, 2011 at 1:17 am

Is the opt folder from home or from current directory?


7 friv February 7, 2012 at 4:51 am

Please detail what is “-zcvf” of “tar -zcvf dir.tar.gz dir” command?


8 savitha A February 21, 2012 at 11:48 am

x specifies to exact a directory


9 jerome March 1, 2012 at 5:12 pm

1. Put on a rad hat.
2. Use Debian
3. cd dir; unzip *.zip


10 mediafire March 2, 2012 at 12:16 pm

what is complete path of unzip command ?


11 bobbutts August 12, 2012 at 5:14 pm

You can always find the path by running
which (commandname)

so like

# which unzip


12 Hari Kiran March 28, 2012 at 12:50 pm



13 ravi September 13, 2012 at 6:13 pm

how to uncompress rootfs file


Leave a Comment

Tagged as:

Previous Faq:

Next Faq: