Bash command to compress folder(s) with a password

zip -er filename.zip dir2 dir4

The zip command is widely available; if not on your system, look for a zip package or similar.

The -e flag specifies encryption is to be used on the zipfile; you'll be prompted for a password.

The -r flag specifies recursion; all the files in dir2 and dir4 will be included.

The resulting zipped, encrypted file containing dir2 and dir4 will be placed at filename.zip.