How to Zip (or) Tar/Gzip an Entire Directory Tree

Posted on October 26, 2007

This is pretty simple once you know the exact syntax, but if you rarely use this OS functionality, it can be a pain to lookup each time. Let’s assume we have a directory in /data, called “backup”. Within it, many subdirectories and files exist.

We’d like to zip (or tar/gzip) the entire directory’s contents. Here’s how to:

Zip the Directory (recursively)

cd /data
zip -r backup.zip backup/

Tar/Gzip the Directory (recursively)

cd /data
tar -v -cf backup.tar backup
gzip backup.tar

And there you have it.