Word – Bash command to compress folder(s) with a password

bashgzippasswordszip

How can I compress two folders into archive file (zip, gzip or something like that) with a password on the files?

For example I have folder structure:

  • rootDir
    • dir1
    • dir2
    • dir3
    • dir4

I need bash command to add dir2 and dir4 to same archive file compressed with a password on it.

Best Answer

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.

Related Question