Some useful Linux tips for users that want the most out of the command-line. How to work with zipfiles.

Posted: August 20, 2013. At: 5:33 PM. This was 4 years ago. Post ID: 6143

How to unzip files into a specific directory on your system.

Just type the unzip command like this: unzip [zipfile.zip] -d [directoryname]

homer@deep-thought ~/Downloads $ unzip gzdoom-bin-1-8-02.zip -d myfolder/
Archive:  gzdoom-bin-1-8-02.zip
  inflating: myfolder/fmodex.dll
  inflating: myfolder/gzdoom.exe
  inflating: myfolder/brightmaps.pk3
  inflating: myfolder/gzdoom.pk3
  inflating: myfolder/lights.pk3
  inflating: myfolder/licenses.zip

Then if you look in the myfolder directory and you will find your files in the folder.

homer@deep-thought ~/Downloads $ ls myfolder/
total 4.7M
drwxrwxr-x 2 homer homer 4.0K  20-08-13 04:57 pm .
drwxr-xr-x 9 homer homer  12K  20-08-13 04:57 pm ..
-rw-rw-r-- 1 homer homer 240K  11-05-12 01:15 pm brightmaps.pk3
-rw-rw-r-- 1 homer homer 367K  11-08-10 01:54 pm fmodex.dll
-rw-rw-r-- 1 homer homer 3.4M  23-06-13 11:35 pm gzdoom.exe
-rw-rw-r-- 1 homer homer 659K  23-06-13 11:10 am gzdoom.pk3
-rw-rw-r-- 1 homer homer  17K  28-02-09 10:59 pm licenses.zip
-rw-rw-r-- 1 homer homer  17K  11-05-12 01:15 pm lights.pk3

Use the unzip -l [zipfile.zip] command to list the contents of a zipfile. This is a very useful technique.

homer@deep-thought ~/Downloads $ unzip -l gzdoom-bin-1-8-02.zip 
Archive:  gzdoom-bin-1-8-02.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
   375808  2010-08-11 13:54   fmodex.dll
  3534848  2013-06-23 23:35   gzdoom.exe
   245268  2012-05-11 13:15   brightmaps.pk3
   674279  2013-06-23 11:10   gzdoom.pk3
    17131  2012-05-11 13:15   lights.pk3
    17172  2009-02-28 22:59   licenses.zip
---------                     -------
  4864506                     6 files

This is how to extract a single file from a zipfile to the hard drive.

homer@deep-thought ~/Downloads $ unzip -c gzdoom-bin-1-8-02.zip licenses.zip > licenses.zip

You can also read a text file from within a zip file with this command. This is useful when you just want to read the information about the files.

homer@deep-thought ~/Downloads $ unzip -c holyhell.zip HolyHell.txt | less

The zipinfo command will also list the contents of a zipfile for you.

homer@deep-thought ~/Downloads $ zipinfo gzdoom-bin-1-8-02.zip 
Archive:  gzdoom-bin-1-8-02.zip
Zip file size: 2899539 bytes, number of entries: 6
-rw-a--     2.0 fat   375808 b- defX 10-Aug-11 13:54 fmodex.dll
-rwxa--     2.0 fat  3534848 b- defX 13-Jun-23 23:35 gzdoom.exe
-rw-a--     2.0 fat   245268 b- defX 12-May-11 13:15 brightmaps.pk3
-rw-a--     2.0 fat   674279 b- defX 13-Jun-23 11:10 gzdoom.pk3
-rw-a--     2.0 fat    17131 b- defX 12-May-11 13:15 lights.pk3
-rw-a--     2.0 fat    17172 b- defX 09-Feb-28 22:59 licenses.zip
6 files, 4864506 bytes uncompressed, 2898929 bytes compressed:  40.4%

How to grep the contents of a zipfile. This is very easy when you use the zipgrep command.

homer@deep-thought ~/Downloads $ zipgrep "Doom II" cchest4.zip 
cchest4.txt:                             from "Doom II: Hell on Earth" (PC)
cchest4.txt:                             from "Doom II: Hell on Earth" (PC)
cchest4.txt:                             from "Doom II: Hell on Earth" (PC)
cchest4.txt:                             from "Doom II: Hell on Earth" (PC)
cchest4.txt:                             from "Doom II: Hell on Earth" (PC)
cchest4.wad:Binary file (standard input) matches

How to encrypt a zipfile and require a password to open it. Use the zipcloack command for this; you just give it a zipfile as a file argument and it will prompt you for a password to give the file and then it will be encrypted.

homer@deep-thought ~/Downloads $ zipcloak gzdoom-bin-1-8-02.zip 
Enter password: 
Verify password: 
encrypting: fmodex.dll
encrypting: gzdoom.exe
encrypting: brightmaps.pk3
encrypting: gzdoom.pk3
encrypting: lights.pk3
encrypting: licenses.zip

If you want to unzip the encrypted file; just use the unzip command as usual.

homer@deep-thought ~/Downloads $ unzip gzdoom-bin-1-8-02.zip 
Archive:  gzdoom-bin-1-8-02.zip
[gzdoom-bin-1-8-02.zip] fmodex.dll password: 
  inflating: fmodex.dll              
  inflating: gzdoom.exe              
  inflating: brightmaps.pk3          
  inflating: gzdoom.pk3              
  inflating: lights.pk3              
replace licenses.zip? [y]es, [n]o, [A]ll, [N]one, [r]ename: n

No comments have been made. Use this form to start the conversation :)

Leave a Reply