Shell script to unzip a file with a password

I am trying to unzip a file with a given password from the vendor. I need to automate this process so I'd like a command to do it, so that I can write a script.


Solution 1:

To unzip files with password use the -P option:

unzip -P password file.zip

To create a directory with same structure as the source .zip and place contents in it:

unzip -P password file.zip

# output
total 560
drwxrwxr-x   2 george george   4096 Mar  3 14:02 ./
drwxr-xr-x 199 george george  12288 Mar  3 14:01 ../
drwx------   2 george george   4096 Apr 23  2016 file/
-rw-rw-r--   1 george george 150058 Feb 18 07:00 file.zip

To unzip content into current directory without creating one with same structure as source .zip file:

unzip -j -P password file.zip

# output
total 560
drwxrwxr-x   2 george george   4096 Mar  3 14:02 ./
drwxr-xr-x 199 george george  12288 Mar  3 14:01 ../    
-rw-rw-r--   1 george george 150058 Feb 18 07:00 file.zip
-rw-------   1 george george 405115 Apr 23  2016 Transcript.pdf