Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I would like to know whether it is possible to do the following via CLI.

I have a Folder F which contains several sub folders and some files. I want to compress folder F into .zip file with the "password-only-extract".

share|improve this question

2 Answers 2

up vote 7 down vote accepted

Go to the relevant folder using the cd command like this:

cd /path/to/folder/

(If your folder F is in your Home folder, you can just do cd ~.)

Then, type in your terminal:

zip -er F.zip F

This will prompt you for a password. Give it, and that will create a password-protected zip file from that folder.

  • -e enables encryption for your zip file. This is what makes it ask for the password.
  • -r makes the command recursive, meaning that all the files inside the folder will be added to the zip file.
  • F.zip is the name of the output file.
  • F is the folder you want to zip.

There is an option called -P that will allow you to pass the password in the command itself, but that is not good because there is always the threat of over-the-shoulder peeking. Also other users can see the password by using ps -ef command if you use -P switch. With that -P switch, the command will look like this:

zip -P password -r F.zip F
  • Visit man zip for more information.
share|improve this answer
-e means encrypt –  dedunumax Sep 8 '13 at 12:11
Hey I just edited your question to include a little bit of context. But can you edit it to include your -e means encrypt comment, as well as the meaning of the -r option. Thanks! –  Alaa Ali Sep 8 '13 at 12:16
thanks Alaa that was a nice edit. I'll edit it again. –  dedunumax Sep 8 '13 at 12:18
Tx Dedunu for your input.Just one more clarification needed.What if I need to automate this ...What I mean is if instead of prompting for a password can I set a password in the command itself ? –  UnderDog Sep 8 '13 at 12:19
I added that also. –  dedunumax Sep 8 '13 at 12:24

The encryption of zip files is weak and can be broken very easily. Instead use 7zip.

7z a -p1234 -r Fdirectory.7z /path/to/F
  • a command tells 7zip to add files.
  • -p switch asks for password.
  • -r means recursive.
  • Fdirectory.7z is the name of the to-be-created archive.
  • /path/to/F is the path of your directory. It can be relative or full path.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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