Linux - Zip / Unzip

> Procedural Languages > Bash Shell and (Unix|Linux) Utilities (XCU)

1 - About

The zip manager in Linux

Compression:

  • take advantage of redundancy between files.

split archives:

  • storing a large archive on multiple removable media.
  • split big file ?

3 - How to

3.1 - List

List the content

unzip -l myFile.zip

Example:

/usr/bin/unzip -l p25797429_111190_Linux-x86-64.zip
Archive:  p25797429_111190_Linux-x86-64.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
        0  04-12-17 08:55   25797429/
    68000  04-12-17 08:55   25797429/p21517672_111190_Generic.zip
318682896  04-12-17 08:30   25797429/p25710656_111190_Linux-x86-64.zip
545626254  04-12-17 08:55   25797429/p25818798_111190_Generic.zip
456596466  04-12-17 08:33   25797429/p25710602_111190_Linux-x86-64.zip
182417792  04-12-17 08:55   25797429/p25738050_111190_Generic.zip
   114984  04-15-17 20:38   25797429/README.html
1052740398  04-12-17 08:55   25797429/p25710734_111190_Generic.zip
 91360658  04-12-17 08:55   25797429/p24346370_111190_Generic.zip
1036787935  04-12-17 08:36   25797429/p25796832_111190_Linux-x86-64.zip
 --------                   -------
3684395383                   10 files
Advertising

3.2 - Unzip all zip files of a directory

/usr/bin/unzip \*.zip
  ..........
  ..........
  inflating: 13952743/files/common/script_handlers/MDS_handler.py
  creating:  13952743/files/clone/
  creating:  13952743/files/clone/provision/
  inflating: 13952743/files/clone/provision/adf_t2p_registration.xml
  inflating: 13952743/files/clone/provision/adf-t2p-cloner.jar
  inflating: 13952743/README.txt

9 archives were successfully processed.

3.3 - Zip a directory recursively

/usr/bin/zip -r targetFile.zip ./targetDir/*

3.4 - Zip a file

zip targetFile.zip /myFile

3.5 - Unzip in a target directory

unzip file.zip -d myTargetDirectory

3.6 - Zip only a subset of a files

Under Unix, the option [email protected] file list can be used to powerful effect in conjunction with the find command.

For example, to archive all the C source files in the current directory and its subdirectories:

find . -name "*.[ch]" -print | zip source -@

4 - Support

4.1 - unzip: cannot find or open

You may get this kind of message:

unzip:  cannot find or open ./p25797429_111190_Linux-x86-64.zip, ./p25797429_111190_Linux-x86-64.zip.zip or ./p25797429_111190_Linux-x86-64.zip.ZIP.

Just try to use another unzip application.

Example:

/usr/bin/unzip
Advertising