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

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

Let' s archive and compress the same directory with bzip2
$ tar -cvpjf

And what is the size of the compressed archive?
$ du -h 
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