7-zip is an open source utility for manipulating archives. Formats 7z, ZIP, GZIP, BZIP2 and TAR are supported fully, other formats can be unpacked.

# To archive a file or folder:
7z a <archived.7z> <path/to/file>

# To encrypt an existing archive (including headers):
7z a <encrypted.7z> -p<password> -mhe <archived.7z>

# To extract an existing 7z file with original directory structure:
7z x <archived.7z>

# To extract an archive with user-defined output path:
7z x <archived.7z> -o<path/to/output>

# To archive using a specific archive type:
7z a -t <zip|gzip|bzip2|tar|...> <archived.7z> <path/to/file>

# To list available archive types:
7z i

# To list the contents of an archive file:
7z l <archived.7z>