I need to unzip a .zip file which is password protected using Terminal

I am able to unzip the .zip file (if it is not password protected) using this command

unzip /Users/vikas/Desktop/as.zip -d /Users/vikas/Desktop/new\ folder

Note: I need to pass the password in the command. I know when it asks for the password, but my scenario is different as I have to pass the password in the command itself (e.g. -p "my password" in Linux).

  • unzip prompts for the password when needed. – greg-449 Jan 7 '16 at 11:26
  • I need to pass the password in the command. Reason is that I am working on an application that has a function to load data from zip file and I have to pass the whole command as one line – Vikas Bansal Jan 7 '16 at 11:28

Use the -P password argument to pass the password to unzip:

unzip -P password /Users/vikas/Desktop/as.zip -d /Users/vikas/Desktop/new\ folder
| improve this answer | |
  • I keep getting a "Filename not matched"on the target dir – Mathijs Segers Jul 2 '18 at 13:57

you can use "Unarchiver" for it, works perfect.

| improve this answer | |
  • 4
    Is unarchiver a terminal command? If it is an example would help, if it is not then it does not answer the question. – Solar Mike Dec 4 '17 at 9:57

In case of AES encryption unzip won't work. In such case 7z do the trick perfectly:

7z x <archive_name>
| improve this answer | |
  • 1
    You can also enter the password on the command line instead of waiting for 7z to prompt for it, e.g. 7z x <archive_name> -pPASSWORD - there's no space after the -p. – Andrew Morton Sep 6 '19 at 9:00

Sometime, unzip command doesn't work for me, so replace unzip with ditto will solve issue:

ditto -V -x -k --password --sequesterRsrc --rsrc FILENAME.ZIP DESTINATIONDIRECTORY
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.