Create a tar.gz Archive using macOS Terminal

Tar is short for Tape Archive and is unique in that you can pick between different compressions such as gzip, bzip2 or xz.

Archive

Example 1 - gzip Compression

-c Create
-p Preserve Permissions (extract all protection information)
-v "Verbose mode" lists every file as processed.
-z Filter the archive through gzip
-f Use archive file

tar -cpvzf BackUpDirectory.tar.gz /path/to/directory

Example 2 - bzip2 Compression

Excludes files with a specific extension or characteristic.

-c Create
-p Preserve Permissions (extract all protection information)
-v "Verbose mode" lists every file as processed.
-j Use bzip2 compression.
-f Use archive file
--exclude=*.psd Exclude any Photoshop files.
--exclude=".*" Exclude any hidden files.

tar -cpvjf my_tar_archive.tar.gz /path/to/directory --exclude=*.psd --exclude=".*"

Unarchive

-x Extract files.
-z Filter the archive through gzip
-v "Verbose mode" lists every file as processed.
-f Specify the archive's filename.
-C Extract the files to a specific directory.

tar -xzvf my_tar_archive.tar.gz -C /path/to/directory

Archive Using Zip