TOOL » LINUX » PACKAGE

Tar

Usage

shell
tar OPTIONS SOURCE

On options, hyphen is optional.

OptionDescription
-c --createCreate tar file.
-x --extract --getExtract tar file.
-t --listList the contents of an archive.
-C --directorySet current directory.
-f --fileSet the name of the file to create / extract.
-h --dereferenceFollow symlinks; archive and dump the files they point to.
-a --auto-compressUse archive suffix to determine the compression program.
-I --use-compress-programUse a custom program to compress.
-J --xzEnable xz algorithm.
-z --gzip --gunzip --ungzipEnable gnuzip algorithm.
--zstdEnable zstandart algorithm.
-v --verboseVerbosely list files processed.

Gzipped files can have .tgz or .tar.gz extensions.

Xz files have .tar.xz extension.

Zstandart files have .tar.zst extension.

Examples

Compress a folder:

shell
tar -cf grouped.tar myfolder                        # Create file
tar -czf grouped.tgz myfolder                       # Create gzipped file
tar -c --zstd -f grouped.tar.zst myfolder           # Create zstd file
tar -cI 'zstd -19 -T0' -f grouped.tar.zst myfolder  # Create zstd file (best compression)

Extract gzipped file:

shell
tar -xf file.tar
tar -xzf file.tgz
tar -x --zstd -f file.tar.zst

List files in tar file:

shell
tar -tf file.tar

Compress with zstd and encrypt with gpg, then the inverse operation:

shell
tar --zstd -c Folder/ | gpg -e --default-recipient-self > folder.tar.zst.gpg
gpg --decrypt folder.tar.zst.gpg | tar --zstd -x