mandri Posted February 14, 2008 Report Share Posted February 14, 2008 (edited) I tried to search for the answer to this,zip -e nothing to do,but I keep getting errors I only used 3 letters. Other combinations of those keywords gave very irrelevant results. Simple question. How do I create and password protect a zip file? I have a directory named test on my desktop. Inside this directory are a few more directories of copied data just for this test. I opened a terminal and enter zip -e /home/mandri/Desktop/test. After entering and confirming a password,I get the error "nothing to do!". I tried opening a terminal in the directory I want to zip,I get this error. "Invalid command arguments (cannot write zip file to terminal)". What am I doing wrong here? Also,is there a way in linux to create a password protected .rar file? I can create the .rar easy enough,but how can a password be added? I also know about GPG allowing the password,but I don't want to encrypt it,just simply add a password. Thanks. Edited February 15, 2008 by mandri Quote Link to comment Share on other sites More sharing options...
neddie Posted February 14, 2008 Report Share Posted February 14, 2008 For a single file: cd Desktop zip -e test.zip test.txt For multiple files you can use test/* instead of test.txt For recursive subdirectories I guess you'll need to pipe the output of find into the input of zip. But I've not tried this. Quote Link to comment Share on other sites More sharing options...
mandri Posted February 14, 2008 Author Report Share Posted February 14, 2008 (edited) I am still not getting nowhere with this. I have tried this as well xxxx]$ cd /home/mandri/Desktop/test test]$ zip -e >/home/mandri/Desktop/test.zip That accepts the password,and creates a zip archive on my desktop. The terminal just stalls at the line adding: - and the zip archive remains at 0 bytes. I also tried this cd Desktop Desktop]$ zip -e test >test bash: test: Is a directory For recursive subdirectories I guess you'll need to pipe the output of find into the input of zip. But I've not tried this. So I then tried this Desktop]$ zip -e test >test.zip Enter password: Verify password: zip warning: missing end signature--probably not a zip file (did you zip warning: remember to use binary mode when you transferred it?) zip error: Zip file structure invalid (test.zip) I also tried this Desktop]$ zip -e test >test/* bash: test/*: ambiguous redirect Then this Desktop]$ zip -e test/* >test.zip Enter password: Verify password: This seemed to finish,and it created a zip archive on my desktop,and I didn't see it stall at adding: - like earlier. But the zip archive is still 0 bytes.There's nothing in it. I should add because you gave examples of .txt,I am trying to zip an entire directory(a folder containing a few other folders)one folder with wallpapers,another folder with pictures from my camera,and also including text files within the parent directory,which is /home/mandri/Desktop/test And oh yeah,I'm getting so caught up in this,I almost forgot to say thanks for replying. So THANKS. :) EDIT Desktop]$ zip -e test/* >test.zipEnter password: Verify password: This seemed to finish,and it created a zip archive on my desktop,and I didn't see it stall at adding: - like earlier. But the zip archive is still 0 bytes.There's nothing in it. I seen there was a file size of 118 bytes,not near enough for the wallpapers and .jpegs. When I try to open it,I get the error "Could not open the file, probably due to an unsupported file format". Using ark,I get "an error occured when trying to open the archive". I have since tried this too,no luck. cd Desktop Desktop]$ zip -e -r test >test2.zip Enter password: Verify password: zip error: Nothing to do! (test.zip) Desktop]$ zip -e -R test >test2.zip Enter password: Verify password: zip error: Nothing to do! (test.zip) Desktop]$ Edited February 14, 2008 by mandri Quote Link to comment Share on other sites More sharing options...
mandri Posted February 15, 2008 Author Report Share Posted February 15, 2008 (edited) OK.I got it!Kind of. :D I kept messing with this until I found something that worked. OK.I did read a lot too!!! Using this command cd Desktop Desktop]$ zip -e -r test.zip test test Enter password: Verify password: adding: test/ here it added everything found in the directory named test,all the subdirectories,text files,everything That created a password protected zip file named test.zip. Now when I want to extract the file,it asks for the password,That's good. Even with using ark,if I want to open any file within the archive,it asks for the password.That's good. Only one problem left. That is when using ark,the archive will still open and all the file names are readily available,and listed in a tree view,even if you can't open the individual files to see their content without the password. How can I prevent ark from even opening the archive at all without the password? I suppose if all the file names were changed to something else that didn't identify the contents before they were archived,it wouldn't matter if the file names were easily exposed. That is yet another matter,and I think I'd be getting off course taking that route. This isn't a top secret experiment here. I could just as easily encrypt it with gpg if that were the case. Any ideas anyone? If not,I'll keep working at this,and post what I've found,if I find anything. Thanks. EDIT For a single file: cd Desktop zip -e test.zip test.txt This didn't work with the test.txt.See below. But you did clue me in with test.zip at the beginning rather than at the end. Desktop]$ zip -e test.zip test.txt Enter password: Verify password: zip warning: name not matched: test.txt zip error: Nothing to do! (test.zip) This worked. Desktop]$ zip -e test.zip test test Enter password: Verify password: adding: test (deflated 5%) Edited February 15, 2008 by mandri Quote Link to comment Share on other sites More sharing options...
neddie Posted February 15, 2008 Report Share Posted February 15, 2008 zip -e >/home/mandri/Desktop/test.zipzip -e test >test zip -e test >test.zip zip -e test >test/* zip -e test/* >test.zip zip -e -r test >test2.zip zip -e -R test >test2.zip What are you doing? Why are you trying so many random options instead of just trying what I suggested? :unsure: It's quite easy, just follow my example for a single file and then work up from there. And check the man pages if you're not sure, rather than just pressing keys at random. You're making this much harder for yourself than it needs to be. And yes, however you put a password in a zip file, you will always be able to see the filenames and file sizes. That's just the way the zip format works. If you want it more secret then either pack a zip file inside a password-protected zip, or use something like mcrypt. Quote Link to comment Share on other sites More sharing options...
mandri Posted February 17, 2008 Author Report Share Posted February 17, 2008 I did try as you suggested,but it didn't work.Sorry. :P cd Desktop Desktop]$ zip -e test.zip test.txt Enter password: Verify password: zip warning: name not matched: test.txt zip error: Nothing to do! (test.zip) So I tried random entries until I found this one that did. cd Desktop Desktop]$ zip -e test test Enter password: Verify password: adding: test (deflated 50%) Desktop]$ Once I found that this worked,adding the option -r included all the files and sub-directories in a more complex scenario. If you want it more secret then either pack a zip file inside a password-protected zip That is a fine idea,no need for mcrypt. :) Quote Link to comment Share on other sites More sharing options...
neddie Posted February 17, 2008 Report Share Posted February 17, 2008 zip -e test.zip test.txt zip warning: name not matched: test.txt zip error: Nothing to do! (test.zip) That's telling you that you haven't got a file called test.txt. What I gave you was just an example, if you haven't got a file with exactly that name then you could have either made a simple text file with this name, or edited the command to give a filename which you have got. Like I said, start simple and work upwards. Good work finding the -r option though. Quote Link to comment Share on other sites More sharing options...
mandri Posted February 17, 2008 Author Report Share Posted February 17, 2008 (edited) That's telling you that you haven't got a file called test.txt. Yes,I now see what you mean. That is what had me confused.As far as I knew,I didhave a file named test.txt. I had only created a new text file,and named it test. Not test.txt as in your example. I assumed a text file would automatically be given the file extension .txt. I do have to stop assuming things like this. Since I've see that your example does work,I have yet tried two more deviations from the example you have given,using the file named test.txt. Both have also worked. 1.zip -e test test.txt This gave the same result,a zip file named test.zip 2.zip -e file test.txt This gave the zip file the name file.zip rather than test.zip So do I have this right now? 1.The first parameter is what you want the zip file to be named,and the second(and additional) parameter(s) is the file(s) you want to zip. 2.It's not necessary to specify .zip in the first parameter,as my above examples did work,because Zip will give it the .zip extension anyway. Thanks for your time and being persistant with me. I now have to get a new keyboard. The letter z is worn off. Edited February 17, 2008 by mandri Quote Link to comment Share on other sites More sharing options...
neddie Posted February 17, 2008 Report Share Posted February 17, 2008 So do I have this right now?1.The first parameter is what you want the zip file to be named,and the second(and additional) parameter(s) is the file(s) you want to zip. Yes2.It's not necessary to specify .zip in the first parameter,as my above examples did work,because Zip will give it the .zip extension anyway.Yes. I find it a bit weird but that's what the man page says. Also I'm surprised that Ark can't make password-protected zips - it can prompt for a password when given one made by zip, but I can't find any options to create a password-protected zip from Ark. Odd. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.