archive and compress a directory

I always forget the tar flags --"function letters" to archive and compress at once. I always need to login to that backup box and look at that ancient backup script or --help , or man , or google for that GNU howto. Let 's put it on my alog.

some common tar flags:
$  tar --help | egrep " -c, | -u, | -v, | -z, | -Z, | -j, | -p, | -f, | -x,"
  -c, --create               create a new archive
  -u, --update               only append files newer than copy in archive
  -x, --extract, --get       extract files from an archive
  -p, --preserve-permissions, --same-permissions
  -f, --file=ARCHIVE         use archive file or device ARCHIVE
  -j, --bzip2                filter the archive through bzip2
  -z, --gzip, --gunzip, --ungzip   filter the archive through gzip
  -Z, --compress, --uncompress   filter the archive through compress
  -v, --verbose              verbosely list files processed
$


To archive and compress with gzip a directory
$ tar -cvpzf ipduh.com.tar.gz ipduh.com

The ipduh.com directory is approximately 90% ASCII and 10% binary files.
Let 's compare the directory and the compressed archive sizes.
$ du -h --max-depth=0 ipduh.com
8.5G ipduh.com
$ du -h ipduh.com.tar.gz
774M ipduh.com.tar.gz
$
This is a good compression rate.

Let' s archive and compress the same directory with bzip2
$ tar -cvpjf ipduh.com.tar.bz2 ipduh.com

And what is the size of the compressed archive?
$ du -h ipduh.com.tar.bz2 
545M ipduh.com.tar.bz2
That's a better compression rate, but it takes more time.


notes on archiving and compression --that GNU howto

archive and compress a directory linux