Files Compression

July 2016 ยท 1 minute read

These are steps to create and extract compressed files in different format, tar, zip, and 7z.

Tar

Already installed in most linux distributions

Compress

$ tar -zcvf filename.tgz files/directories

Extract

$ tar -zxvf foo.tgz

z: is for tgz. don’t put z if you want to use tar format

Zip

Install

$ sudo aptitude install zip

Compress files

$ zip compressed.zip uncompressed_files

Compress a folder

$ zip -r compressed.zip uncompressed_folder

Extract

$ unzip compressed.zip

7z

Install

$ sudo aptitude install p7zip-full

Compress

$ 7za a compressed.7z uncompressed_files

Extract

$ 7za x compressed.7z

Note: install p7zip-full instead of p7zip, to use 7z archiver as a command line utility.

Bash script to compress folders separated by their names

#!/bin/bash
for folder in */
do
    7z a -mx9 -mmt "${folder%/}.7z" "$folder"
done

References: