I tried to gzip a directory with the following command:
gzip -r /home/path/to/backups/mydirectory.gz /home/site/public_html/
I was expecting to see a .gz file show up inside …backups containing all the files found in …public_html. This isn't what happened. Instead, every file was (recursively) renamed to [filename].gz within public_html. This, obviously, brought an entire site down.
Two questions: 1) What did I do wrong with the syntax? and 2) How can I revert all of the filenames back to what they were before (exactly what they are now, minus the .gz extension).
Best Answer
Gzip only compresses individual files; it's not an archiving tool. It's usually used in combination with something like tar. In fact, some versions of
tar
will usegzip
to automatically create a compressed archive if given appropriate flags. For example:This creates (
-c
) a gzip-compressed (-z
) archive calledpublic_html.tar.gz
containing the contents of the specifiedpublic_html
directory.Just run
gunzip
on all the files. E.g:Note that you can also simply use the
zip
command, which will create a single compressed archive.