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.
Syntax:
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
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- My 10 UNIX Command Line Mistakes
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
- Email FAQ to a friend
- Download PDF version
- Printable version
- Comment RSS feed
- Last Updated: 05/29/07



{ 2 comments… read them below or add one }
Questions;
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?
Thanks
how to gzip all the files undre one dictory?
For example:
i have a dir /home/suren/dir
in this i have files
file1
file2
file3
from /home/suren/ i want to execute a command to gzip all files under dir.