Shell script to unzip a file with a password

34,833

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 
Share:
34,833

Related videos on Youtube

Gangadhar Lankella
Author by

Gangadhar Lankella

Updated on September 18, 2022

Comments

  • Gangadhar Lankella
    Gangadhar Lankella over 1 year

    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.

    • George Udosen
      George Udosen about 7 years
      Try this: unzip -P password file.zip