Archiving

tar

bundle multiple files and directories into a single archive

# Options
# -c – Create an archive file.
# -x – Extracts files from an archive.
# -z – Adds gzip compression when creating or extracting an archive file.
# -j – Adds bzip2 compression when creating or extracting an archive file.
# -t – Lists the contents of an archive file.
# -u – Update files to an existing archive.
# -r – Append files to an archive, similar to the -u option.
# -A – Link two archives into a single archive.
# -v – activates verbose mode, providing detailed output throughout the archiving process.
# -f – specifies the name of the new archive file.

# Usage
tar -cvf archive.tar file1 file2 # compress to .tar archive
tar -cvf archive.tar directory1/ # compress to .tar archive
tar -czvf archive.tar.gz file1 file2 directory1 # '.tar.gz' or '.tgz' compression

tar -xvf archive.tar # un-compress tar
tar -xvf archive.tar.gz -C /path/to/destination/ # un-compress to specific directory

zip and unzip

# Options
# -d - Delete a file from the zip
# -u - Update a file from the zip
# -r - recursive zip
# -x - exclude file from zipping


# Usage
zip sampleZipFile.zip ExampleFile.txt ExampleFile1.txt # Create a compressed zip file
zip –r sampleZipFile.zip MyDirectory # Recursive zip of the directory
zip –d sampleZipFile.zip ExampleFile.txt # Remove a file from zip

unzip sampleZipFile.zip
unzip -d sample.zip destinationDirectory/ # uncompress to a specific directory

OS and packages

apt install tar zip unzip  # Debian/Ubuntu
yum install tar zip unzip  # CentOS/Fedora (DNF, MicroDNF, RPM, Yum)
pacman -S tar zip unzip    # Arch (Pacman)
apk add tar zip unzip       # Alpine
brew install gnu-tar zip unzip # macOS