When taring files and directories the chances are you will want to compress the archive as well. Here’s how to do it quickly, in a single command:
tar -czvf archive.tgz directory
Let’s break it down
First we are taring “directory”, the “-c” parameters tells tar to create, “-v” to be verbose and “-f” to specify the archive file for output.
There is one specific parameter in this tar command that is different to your usual use of tar when creating an archive and that’s “-z”. This parameter informs tar to also compress the archive with gzip.
Of course you could also use bzip2, like so:
tar -cjvf archive.tar.bz2 directory
Pretty simple stuff when you know the command, also extremely useful.