Generating a password-protected archive

Generating an archive file from either a file or directory is a cinch using the command-line. Here’s the structure:

zip [options] [archive name] [file or folder to be archived]

While there are many options available, the one we’re interested in is -e, for “encrypted”, like so:

zip -e archive.zip example.txt

To create a password-protected archive from a directory, add the r flag as well:

zip -er archive.zip this-is-a-directory/