Skip to main content

tar

The tar (tape archive) command is used to combine multiple files and directories into a single archive file, often called a tarball. It can also integrate with compression tools like gzip and bzip2 to compress the archive.

Basic Syntax

tar [OPTION...] [FILE]...

Common Options

OptionDescription
-c, --createCreate a new archive.
-x, --extractExtract files from an archive.
-t, --listList the contents of an archive.
-v, --verboseVerbosely list files processed.
-f, --file=ARCHIVEUse archive file or device ARCHIVE.
-z, --gzipFilter the archive through gzip.
-j, --bzip2Filter the archive through bzip2.
-J, --xzFilter the archive through xz.

Real-world Examples

  1. Create an uncompressed archive of a directory:

    tar -cvf backup.tar /path/to/directory
  2. Create a gzip-compressed archive:

    tar -czvf backup.tar.gz /path/to/directory
  3. Extract a gzip-compressed archive:

    tar -xzvf archive.tar.gz
  4. List contents of an archive without extracting:

    tar -tzvf archive.tar.gz