List of various tar commands for your daily uses.

  1. Create an (uncompressed) archive.
  • Create: tar cvf data.tar data/
  • Extract: tar xvf data.tar

2. Create and compress in xz format

Note: xz = LZMA = Lempel–Ziv–Markov chain algorithm

  • Create: tar Jcvf data.tar.xz data/
  • Extract: tar xvf data.tar.xz

3. Create and compress in gzip format

  • Create: tar zcvf data.tar.gz data/
  • Extract: tar xvf data.tar.gz

4. Create and compress in bzip2 format

  • Create: tar jcvf data.tar.bz2 data/
  • Extract: tar xvf data.tar.bz2

5. Create and compress in zip format

  • Create: zip data.zip -r data/
  • Extract: unzip data.zip
  • Extract to a directory: unzip data.zip -d data/
  • Create with password: zip -P <password> data.zip -r data/
  • Unzip with password: unzip -P <password> data.zip

6. To encrypt/decrypt a (tarred) file with openssl

Refer to this post.

7. Create and extract files in lzip format

  • Note: lzip is required and can be installed with for example sudo apt install -yq lzip.
  • Create: tar cvf data.tar data && lzip -v data.tar.
  • Extract: tar --lzip -xvf data.tar.lz, or, lzip -d data.tar.lz && tar xvf data.tar && rm data.tar.