Bash command to compress folder(s) with a password

7

1

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.

Perica Zivkovic

Posted 2009-09-10T17:50:41.643

Reputation: 172

Answers

7

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.

Tim

Posted 2009-09-10T17:50:41.643

Reputation: 522

This is good, how do I do it for all folders , files and subfolders (recursive) ? And another question, how do I provide password without prompt ? – Perica Zivkovic – 2009-09-10T18:01:00.920

2so the answer I was looking for is: zip -rP "password" filename.zip dir2 dir4 – Perica Zivkovic – 2009-09-10T18:42:28.183

1

Note however, that zip's built-in encryption is fairly insecure: http://math.ucr.edu/~mike/zipattacks.pdf . If you want more than protection from casual peeping, use a real encryption software (such as GnuPG or TrueCrypt).

– sleske – 2010-01-04T11:25:23.683

0

Compress with your favorite unix command (mine is 'tar cfj' for a BZip2 tarball).
Then encrypt with bcrypt.

Bcrypt is a cross platform file encryption utility.

But, they say bcrypt is no longer safe (! ;-)),
Well, change to TrueCrypt (it too is cross platform -- easycrypt).

Tip: Encryption after compression makes life much more interesting.

nik

Posted 2009-09-10T17:50:41.643

Reputation: 50 788

what do you mean by "more interesting"? – Tebe – 2015-07-25T14:16:16.453

1This approach is interesting, as it will hide the file list in the compressed file, unlike zipped file. – Technico.top – 2016-10-19T04:28:42.830