gzip
is just a compressor, not a file archiver. I know, it's weird when you're coming from the world of pkzip
, which does both.
What you want to use is tar
, which does recursive archiving of files into one big file, which you can then compress. Generally, you run tar from the parent of the directory you want to archive, something like this:
tar -cvf archive-name.tar directory-to-store/
Which will give you an uncompressed archive. You can then compress that with
gzip archive-name.tar
Which will give you archive-name.tar.gz
.
If you are using GNU tar (and you probably are), you can combine these into one step by adding the z flag:
tar -czvf archive-name.tar.gz directory-to-store/
and you can uncompress with
tar -xzvf archive-name.tar.gz
And in fact, with modern versions of GNU tar, no need to give the -z
for decompression -- it will auto-detect. This is handy, because GNU tar also supports -j
for (better than gzip) bzip2
compression, and (if you have a new enough version) -J
for even-better xz
compression. Normally, you'd give files made that way .tar.bz2
or .tar.xz
extensions, but then it's irritating to have to choose the right flag to uncompress, especially in scripts.