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.

1

2 Answers

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 
0

If you are getting an unsupported compression method 99 error, then your ZIP file is AES encrypted which is currently not supported by unzip. Use 7zip instead (install with sudo apt install p7zip-full):

7za x -p<PASSWORD> file.zip

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest