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
.zip file with the "password-only-extract".
Go to the relevant folder using the
cd command like this:
(If your folder
F is in your Home folder, you can just do
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.
-eenables encryption for your zip file. This is what makes it ask for the password.
-rmakes the command recursive, meaning that all the files inside the folder will be added to the zip file.
F.zipis the name of the output file.
Fis 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
man zipfor more information.
The encryption of zip files is weak and can be broken very easily. Instead use 7zip.
7z a -p Fdirectory.7z /path/to/F
acommand tells 7zip to add files.
-pYou can either, leave it blank so it asks you interactively or type your password here.
Fdirectory.7zis the name of the to-be-created archive.
/path/to/Fis the path of your directory. It can be relative or full path.
Is recommendable not typing the password in the shell since it's visible to anyone with access to the