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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 17 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
17 comments… add one
  • AD Feb 27, 2009 @ 13:19


    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?


    • hung Feb 29, 2016 @ 4:06

      thank you :)

  • suren Jul 13, 2009 @ 13:46

    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.

    • Zhiping Jun 13, 2010 @ 11:32

      tar -zcvf dir.tar.gz dir

      • SANJAY TEJANI Dec 16, 2010 @ 9:36


        • savitha A Feb 21, 2012 @ 11:46

          tar -xzf dir.tar.gz

        • seth Sep 11, 2016 @ 21:30


  • charles pere Aug 9, 2011 @ 1:17

    Is the opt folder from home or from current directory?

  • friv Feb 7, 2012 @ 4:51

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

  • savitha A Feb 21, 2012 @ 11:48

    x specifies to exact a directory

  • jerome Mar 1, 2012 @ 17:12

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

  • mediafire Mar 2, 2012 @ 12:16

    what is complete path of unzip command ?

    • bobbutts Aug 12, 2012 @ 17:14

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

      so like

      # which unzip

  • Hari Kiran Mar 28, 2012 @ 12:50


  • ravi Sep 13, 2012 @ 18:13

    how to uncompress rootfs file

  • Jerusalem Jul 25, 2020 @ 22:27

    How can I rename all files in multiple zip files?

    • 🐧 Vivek Gite Jul 26, 2020 @ 6:31

      There is no easy way. You can write a shell script to do it:

      1. Unzip file
      2. Rename file as per need
      3. Zip it again

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum