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.
-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

Extract gzipped file:

shell
tar -xzf file.tgz

List files in tar file:

shell
tar -tf file.tar

Compress with zstd and encrypt with gpg:

shell
tar --zstd -cC ~ Folder/ \
  | gpg -e --default-recipient-self > folder.tar.zst.gpg

gpg --decrypt folder.tar.zst.gpg \
    | tar --zstd -xC ~