Zip and unzip utility can be used to compress a file or directory on Mac. These should also work on Ubuntu or other Linux flavours. Here are quick instructions to do it:
Zip a directory/file with password
To zip a directory run the following:
$ zip -er archive.zip dir_to_be_archived Enter password: Verify password: adding: dir_to_be_archived/ (stored 0%) adding: dir_to_be_archived/file1.txt (stored 0%)
It will ask you to enter a password and will not echo it. In case you want to specify password on command line, you can use -P
$ zip -P password123 -r archive.zip dir_to_be_archived adding: archive.zip (stored 0%) adding: dir_to_be_archived/ (stored 0%)
To zip a file with password:
$ zip -P password123 file.zip file_to_be_archived
Unzip an archive with password
To unzip simply double click on zip file and enter the password. From command line simply use unzip
$ unzip archive.zip
or with password on command line
$ unzip -P password123 archive.zip
In case you want to extract archive to a specific directory use:
$ unzip -P password123 archive.zip -d /some/destination/dir