Tar Usage

From Gruff Goat Wiki
Jump to: navigation, search

Tar creates and manipulates streaming archive files. Tar can be easily used with tape drives or files. All of the commands listed below assume you are working with files. These are some command I typically use.

Create Archive

tar -czvf /archivename /directory_to_archive
  # c - Create new archive
  # z - Compress archive using gzip
  # v - Verbose output
  # f - Archive to file, filename must follow.

Extract Archive

tar -xzpvf /archivename
  # x - Extract archive
  # z - Uncompress archive using gzip
  # p - Preserve file permissions, owners, groups, and others
  # v - Verbose output
  # f - Archive from file, filename must follow.

Create Multi-volume Archive

This command creates tar and gzipped multiple files of 80 Mb in size. The mutliple files have names of the form 'archivename_XX' where XX follows the series aa, ab, ...az, ba, bb, ...bz, ...za, zb, ...zz.

tar -czvf - /directory_to_archive | split -b 80m - archivename_
  # c - Create new archive
  # z - Compress archive using gzip
  # v - Verbose output
  # f - Archive to file, filename must follow
  # The dash '-' in place of a file name indicates standard output or standard input

Extract Multi-volume Archive

cat archivename_* | tar -xzpvf -
  # x - Extract archive
  # z - Uncompress archive using gzip
  # p - Preserve file permissions, owners, groups, and others
  # v - Verbose output
  # f - Archive to file, filename must follow
  # The dash '-' in place of a file name indicates standard output or standard input