2022/12/01
To generate an archive out of the contents of a specified folder:
$ tar --create --verbose --file=output.tar directory/
# Shortened:
$ tar cvf output.tar directory/
To generate an archive out of the contents of a specified folder, then compress the archive:
# GZip:
$ tar cvf --gzip output.tar.gz directory/
$ tar cvzf output.tar.gz directory/
# LZMA:
$ tar cvf --lzma output.tar.xz directory/
$ tar cvJf output.tar.xz directory/
# BZip2:
$ tar cvf --bzip2 output.tar.bz directory/
$ tar cvjf output.tar.bz directory/
# Compress:
$ tar cvf --compress output.tar.Z directory/
$ tar cvZf output.tar.Z directory/
# ZStandard:
$ tar cvf --zstd output.tar.zstd directory/
# LZOP:
$ tar cvf --lzop output.tar.lzo directory/
# LZip:
$ tar cvf --lzip output.tar.lzip directory/
To decide the format or version of the tar archive:
# v7
$ tar cvf output.tar directory/ --format=v7
$ tar cvf output.tar directory/ -H v7
# ustar
$ tar cvf output.tar directory/ -H ustar
# pax interchange
$ tar cvf output.tar directory/ -H pax
$ tar cvf output.tar directory/ -H posix
$ tar cvf output.tar directory/ --posix
# oldgnu <= 1.12
$ tar cvf output.tar directory/-H oldgnu
# gnu
$ tar cvf output.tar directory/ -H gnu