Archive under Linux (tar, gz, bz2, zip)

From Thomas-Krenn-Wiki
Jump to: navigation, search

On Linux-based operating systems, different archive formats are available. This article shows a list of the most common archive formats and the their parameters.

tar

The program tar originally stands for Tape Archiver, it was used to back up data to tape drives. It is still very popular and widespread today. A pure tar archive is not compressed.

  • Extract an archive:
tar xfv archive.tar
Legend: (x = extract, f = file, v = verbose)
  • Create an archive with files or folder:
tar cfv archive.tar file1 file2 file3
Legend: (c = create)
  • Create compressed archives:
tar cfzv archive.tar file1 file2 file3
Legend: (z = compress with gzip)
  • Show all files of an archive:
tar tvf archive.tar
  • We refer you to the manpage of tar for more information and parameters:
man tar

gz, bzw. gzip

As we know, a tar archive is not compressed without additional options, this can be done with the additional option gzip. gzip stands for GNU zip and the file extension .gz is appended to the tar archive.

  • Create a compressed file:
gzip file
Result: file.gz
  • Decompress a file:
gunzip file
  • Combining files in a compressed archive:
tar cfvz archive.tar.gz file1 file2
Result: archiv.tar.gz
  • Decompress and extract an archive:
tar xfvz archive.tar.gz

bz2, bzw. bzip2

Besides gzip there is also bzip2, it is very similar to gzip, but uses a different algorithm.

  • Create a compressed file:
bzip2 file
Result: file.bz2
  • Decompress a file:
bunzip2 file.bz2
  • Combining files in a compressed archive:
tar cfvj archive.tar.bz2 file1 file2
Result: archive.tar.bz2
  • Decompress and extract an archive:
tar xfvj archive.tar.bz2

zip

The tool zip is mainly used in Windows , but is also available for Linux-based operating systems.

  • Combining individual files in a compressed archive:
zip archive.zip file1 file2
  • Combining complete folders in a compressed archive:
zip -r archive.zip folder1 folder2 folder3
  • Decompress and extract an archive:
unzip archive.zip
  • Show all files of an archive:
unzip -l archive.zip

Author: Thomas Niedermeier

Related articles

Backup on Linux with duply
Linux Kernel Versions
SSD Secure Erase