Installation

_$: apt-get install p7zip-full

Compression

a) Without password

_$: 7z a folder.7z folder/
_$: 7z a file.7z file
_$: gzip file
_$: tar -zcvf file.tar.gz file

b) With password

_$: 7z a folder.7z folder/ -p
_$: 7z a file.7z file -p

Example: Compress all .log files from the current directory

_$: for f in ./*.log
do
    base=$(basename $f ".log")
    7z a $base.zip $base.log
done

Decompression

_$: 7z e file.7z                # Extract file.7z   in . (here)
_$: 7z x folder.7z              # Extract folder.7z in . (here)
_$: 7z x file.7z -ofolder       # Extract file.7z   in ./folder
_$: gunzip file.gz
_$: tar -zpxvf folder.tar.gz
_$: tar -xf    folder.tar.xz

Example: Decompress all .zip files from a certain directory

_$: FOLDER="unzipped"
_$: for f in ./${FOLDER}/*.zip
do
    7z x $f -o${FOLDER}
done

Archive

_$: tar -cvf file.tar   file
_$: tar -cvf folder.tar folder

Unarchive

_$: tar -xvf file.tar
_$: tar -xvf folder.tar             # Extract the folder directory in ./
                                    # so that files will be in ./folder/...
_$: tar -xvf folder.tar -C /path    # Extract the folder in /path
                                    # so that files will be in /path/folder/...

Inspect files in an archive

_$: tar -tvf file.tar
_$: tar -ztvf file.tar.gz
_$: tar -jtvf file.tar.bz2
_$: 7z l file.7z
_$: 7z l folder.7z

Backups

7zip does not save either the user or the group of the files it compress, so it is not valid, on its own, to create backups: you must use it with tar. The logical order is to first create an archive with tar and then compress said archive using 7z.

Create backup:

_$: tar cf - directory | 7z a -si directory.tar.7z

Restore backup:

_$: 7z x -so directory.tar.7z | tar xf -