Sunday, May 19, 2024
143
rated 0 times [  143] [ 0]  / answers: 1 / hits: 167893  / 2 Years ago, tue, august 9, 2022, 10:33:13

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


More From » command-line

 Answers
6

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.


[#29546] Wednesday, August 10, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
oneeme

Total Points: 340
Total Questions: 110
Total Answers: 133

Location: Ghana
Member since Fri, Oct 21, 2022
2 Years ago
oneeme questions
Wed, Jul 6, 22, 17:32, 2 Years ago
Tue, Mar 15, 22, 05:29, 2 Years ago
Tue, May 10, 22, 17:15, 2 Years ago
Mon, Sep 27, 21, 15:42, 3 Years ago
;