24

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).

2
  • unzip prompts for the password when needed.
    – greg-449
    Jan 7, 2016 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 Jan 7, 2016 at 11:28

4 Answers 4

31

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
3
  • I keep getting a "Filename not matched"on the target dir Jul 2, 2018 at 13:57
  • For me worked on ubuntu (20.04 focal) only "7z x <archive_name>" scheme to unzip password protected file made by (win10 winrar ZIP with pass). Only this asks me for password and not show error "unsupported compression method 99" or "ERROR : Wrong password". Even file manager or zip manager not worked and showed nothing after extraction. Feb 10, 2021 at 13:49
  • 1
    supposed this is your password XlzFWqZL$0$s8w You'll need to do something like this unzip -P 'XlzFWqZL$0$s8w' yourfile.zip Without the quotation, you'll simply get "password incorrect" prompt back. Apr 12, 2023 at 15:32
10

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

7z x <archive_name>
1
  • 2
    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. Sep 6, 2019 at 9:00
5

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

1
  • 5
    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, 2017 at 9:57
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .