Commands
bash
# create
tar czf backup.tar.gz /etc # pack /etc with gzip
tar cJf backup.tar.xz dir # with xz (stronger, slower)
tar czf b.tar.gz -C /var/www site # pack site while inside /var/www (no /var/www/ in paths)
tar czf b.tar.gz --exclude='*.log' --exclude='cache' dir
# extract
tar xzf backup.tar.gz # extract here
tar xzf backup.tar.gz -C /restore # extract into a directory
tar xzf b.tar.gz --strip-components=1 # strip the top directory (common with releases)
tar xzf backup.tar.gz etc/hosts # extract a single file
# view/verify (without extracting)
tar tzf backup.tar.gz | head # the listing
tar tvzf backup.tar.gz # with permissions/sizes/dates
# over the network (no intermediate file):
tar cz dir | ssh host 'tar xz -C /dest' # send a tree to a host (see ssh-client)