Celeb Glow
news | April 04, 2026

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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