MacOS: Compressing files with password in Mac OSX

Operating System, Technology

Problem:

I want to compress all files in a directory and protect the zip file with password.

Solution:

We can do it without installing third party software on Mac OSX like 7zip, iZip, etc.

Step 1: Prepare all files in 1 directory

Step 2: Open Mac terminal and Run ‘zip’ command on mac terminal

Go to the path which contains directory / files. In this case, I want to compress a directory inside: /Users/rajadavid/Desktop/

Then run this command on mac terminal:
zip -erj [filename].zip [directory_to_compress]

-e is to encrypt all files using password;
-r perform compression recursively to all files;
-j remove all internal directory. So the zip file will not store the full path (relative to the current directory).

Sample:

 zip -erj compressed_file.zip /Users/rajadavid/Desktop/compress 

Step 3: Type the password in terminal twice

The compressed file with password protected will be available in: /Users/rajadavid/Desktop/

Further reading:

  • https://stackoverflow.com/questions/24543255/command-line-zip-everything-within-a-directory-but-do-not-include-any-directory
  • https://www.youtube.com/watch?v=UXDLSSTQLJM

Leave a Reply

Your email address will not be published. Required fields are marked *