Tar cheat sheet

Quick Cheat Sheet for TAR Archives

TAR = Tape Archive but it is essentially the native linux format of creating an archive.

Gzip = Compressed. Together a Gzipped Tar is the linux equivalent of a Zip.

To create a gzipped TAR archive of all files in the current directory do this:

tar -czvf archive.tgz *

to tar-gz the xfiles folder into xarchive.tgz do:

tar -czvf xarchive.tgz xfiles/

To extract the archive contents to the current directory do:

tar -xzvf archive.tgz

to extract to a specific existing dir do:

tar -xzvf archive.tgz -C /my/exisiting/path/
Example: backup foder:
bkdate=$(date '+20%y%m%d.%H%M')
tar -cf - /etc /usr/local/bin /home/www | gzip > /home/backup/$bkhost.$bkdate.tar.gz