Easily Compress and/or Encrypt Files in Linux Using 7z Archiver – 7zip ubuntu

p7zip is a port of 7za.exe for POSIX systems like Unix (Linux, Solaris, OpenBSD, FreeBSD, Cygwin, AIX), MacOS X and also for BeOS and Amiga.

7z is an excellent archiving software offering high compression ratio and strong AES-256 encryption.

Installation

Debian/Ubuntu

Open a terminal and type:

apt-get install p7zip-full p7zip-rar

Red Hat/Fedora

yum install p7zip p7zip-plugins

(does not include a RAR plugin)

More here.

Compress (with AES encryption)

7-zip does not store the owner/group of the file, so adding files using tar before 7z is a good practice:

tar cpvf test.tar test/
7z a -p -mx=9 -mhe -t7z test.7z test.tar

Params

a            Add
-p{Password} Set Password
-mx=9        ultra compression
-mhe         encrypt file names
-t7z         file type .7z

If you are interested more for encryption rather than compression (eg when you archive compressed files), this is much more faster (-mx=0 no compression).

7z a -p -mx=0 -mhe -t7z test.7z test.tar

Params

-mx=0   no compression - just add the files

Extract

7z x test.7z

Params

x      eXtract with full paths

GUI front end

Archive Manager (File Roller) will support 7z after p7zip packages installation. To add AES encryption, just provide a (strong) password.

Another option is PeaZip. Just download (latest) portable Linux version from Sourceforge.