Skip to content

tar

tar, or Tape ARchive, is a archiving format and utility first developed for Version 7 Unix in 1977. Itโ€™s original purpose was to collate files into one that can be stored on tape. Similarly, today it is used to bring many files together into a โ€œtarballโ€, which can be compressed with any general data compression algorithm.

Usage

Create a tar archive

Terminal window
tar -cf {archive name} {files listed here}

You can use tar to compress your archive, for example into a .tar.gz or .tar.xz archive. To do this, you either can either use a flag such as -z, -j, or -J (gzip, bzip2, xz), or you can use -a (โ€˜automaticโ€™), which allows it to intuit what algorithm you want from the file extension, such as archive.tar.xz for an xz compressed tarball.

GNU tar can use these compression algorithms

  • gzip (.gz)
  • bzip2 (.bz)
  • xz (.xz)
  • lzip (.lz)
  • lzma (.lzma)
  • lzop (.lzo)
  • zstd (.zstd)

Extract a tar archive

Terminal window
tar -xf {tarball}.tar -C {directory to extract to}

tar can extract from itโ€™s supported compressed formats, such as archive.tar.xz automatically, with no extra flags.