You can do it on your mac without need for 3rd party Apps or Software. I’m currently running macOS High Sierra Version 10.13.6
Objective: We are not assigning password protection to an already compressed (zipped) file. We are creating a new compressed (zipped) file with password protection.
You need to open your “Terminal” application found in…
Applications > Utilities
When opened it should look something like this and it’s ready to accept your keyboard input
|
You need to decide if you are compressing a file or a folder of files?
To avoid any mistyping issues I suggest that you move your file or folder of files you want compressed and password protected to your desktop.
Later I’ll show you how to access you file/s without having to move them on to your desktop first.
NOTE: THERE MUST BE A SPACE BETWEEN EACH NEW COMMAND AND THERE MUST BE NO SPACES IN YOUR FILE NAMES.
|
PRESS “RETURN”
|
ENTER YOUR PASSWORD
NOTE: TERMINAL DOES NOT DISPLAY THE TYPING OF PASSWORDS
PRESS “RETURN”
|
ENTER YOUR PASSWORD AGAIN TO VERIFY IT
NOTE: TERMINAL DOES NOT DISPLAY THE TYPING OF PASSWORDS
PRESS “RETURN”
|
JOB DONE!
The zip file "TheNameYouWantForYourNewZip.zip" was created on your desktop with the password protection you assigned to it.
It’s easy now…
Instead of typing the command “zip -e” type “zip -er”
remembering to point the new command to an actual folder (directory) of files. If the new command doesn’t see a directory of files it won’t work.
So far we’ve put the folders and files on the desktop to avoid any mispelling of long file paths (making our life a little easier whilst learning).
Terminal recognises a space as the start of a new command. Unfortunately our directory path to folders and files may very likely contain spaces. To negotiate this we can escape each unwanted space with a backslash \ .
So now our command to compress a WHOLE DIRECTORY OF FILES located within folders might look something like this…
|
Terminal has a neat trick. Type in your commands to create a zip stopping before you get to the target’s directory path then drag & drop the folder you want zipping into the Terminal window. VoilĂ the file path appears with all spaces escaped.
For the most inquisitive amongst you you’d have noticed Terminal creates the directory paths in your zipped (compressed) file. When you uncompress this file you will see extra files created that contain your compressed files directory paths.
Most people would want to open a compressed .zip file and see only the contents they’re expecting and not be confused by extra files that are irreleveant to them.
NOTE: Terminal does contain a command to remove directory paths -j (junk directory paths) in a .zip file. However there are many problems in trying to use this. It will remove ALL directory paths. Even those you may want in your zipped directory. It also doesn’t work if a file name is duplicated within the hierachy of directories you are trying to zip. So, for this tutorial we’re going to ignore this command.
-j = junk the paths
We’re ignoring this command for this tutorial because in this instance it can create more problems than it solves.
To do this we are going to instruct Terminal to begin from the directory we choose rather than the default “User’ starting point
Currently our default starting point is “Genius-iMac:~ macgenius$” [Computer name] [Current User]
|
Type the command “cd” space (now drag the directory you want to start from into the terminal window) press return.
cd = change directory
|
Now each time we press return our starting point is “Folder with files” until such time we issue the command “cd”space (change directory) again or quit out of Terminal and start again at it’s defaults.
Now we’re working from the file that we actually want to compress so there are no file paths to it. It is our starting point.
With that in mind we add the following commands…
|
PRESS RETURN - JOB Completes
The zip file “TheNameYouWantForYourNewZip.zip” was created on your desktop without any extra user path files contained within it.
If like me and you probably are if you’re a coder you like things tidy and to make sense. Therefore saving your zip file to your desktop only to file it later is not so clever when you can file it instantly with these commands. In my opinion saving your zipped file in the folder you’re compressing would make it easy to find at a later date. A clean desktop is a clean mind ☺
The following not only saves the zipped file into the directory you’re compressing it’s also set to name the file with the same name of the directory that’s being compressed suffixing it with .zip
|
JOB DONE!
The zip file “Folder with files.zip” was created inside the directory you specified as the starting point for Terminal (Folder with files).
IMPORTANT NOTE!
Testing your newly created .zip file you might want to test it on a PC. At first you will be horrified to see that a PC opens your .zip file and displays all of the contents without asking for a password! WTF!
However
remain calm and try to open one of the files displayed. Now, it presents you with a password dialogue box and it does this to each and every file within the .zip. Each file is individually password protected. PC users will know that they can specify to unzip ALL files within a zipped package or just target the one they wish to open by double clicking on it. This means they can open all the files within the .zipped package only having to enter the password once (the same way the mac handles them).
☺
You can get help on different commands (utilities) within mac terminal by typing the command “-help” so “zip -help” and press return reveals the commands and a brief description of their functions
|
Open a fresh terminal window. At your prompt hold down your "escape" key for a couple of seconds.
|
Then type “y”. Terminal will reveal the commands available. You might need to keep pressing “Return” until the full list is revealed.
|
Getting to know the command line
Please share if you find the content useful - thank you
FORUM |
|
Have a comment or something to say? |