Create tar archive and compress in one step

This command will create a tar archive of directory 'dir' and compress it using gzip, the output file will be dir.tgz.

tar cf - dir | gzip -c > dir.tgz