Create
To create a .tgz file, we used tar with the following parameters -czf:
-cor--createwill create a new archive.-z– or--gzipor--gunzipor--ungzipwill filter the archive throughgzipand compress it.-for--file=ARCHIVEwill use archive file or device ARCHIVE. If this option is not given,tarwill first examine the environment variableTAPE. If it is set, its value will be used as the archive name. Otherwise, tar will assume the compiled-in default.
Example:
tar -czf $ARCHIVE_FILE_NAME.tgz $PATH_TO_COMPRESS;
Please note that the order of the parameters will not change the result.
Extract
To extract a .tgz or .tar.gz file using tar we used the following parameters -xzf:
-xor--extract--getwill extract the files from the archive. Arguments are optional. When given, they specify names of the archive members to be extracted.-z– or--gzipor--gunzipor--ungzipwill filter the archive throughgzipand decompress it.-for--file=ARCHIVEwill use archive file or device ARCHIVE. If this option is not given,tarwill first examine the environment variableTAPE. If it is set, its value will be used as the archive name. Otherwise, tar will assume the compiled-in default.
Example:
tar -xzf $ARCHIVE_FILE_NAME.tgz;
This post is also available in: Greek



The following command will create a
tar.xzarchive called repositories.2017.04.20.tar.xz from the folders banana and apple:tar -cJf repositories.2017.04.20.tar.xz banana/ Apple;