How to gzip all files in all sub-directories into one compressed file in bash

Doug picture Doug · Sep 8, 2012 · Viewed 396.6k times · Source

Possible Duplicate:
gzipping up a set of directories and creating a tar compressed file

This post describes how to gzip each file individually within a directory structure. However, I need to do something slightly different. I need to produce one big gzip file for all files under a certain directory. I also need to be able to specify the output filename for the compressed file (e.g., files.gz) and overwrite the old compressed file file if one already exists.

Answer

amitchhajer picture amitchhajer · Sep 8, 2012
tar -zcvf compressFileName.tar.gz folderToCompress

everything in folderToCompress will go to compressFileName

Edit: After review and comments I realized that people may get confused with compressFileName without an extension. If you want you can use .tar.gz extension(as suggested) with the compressFileName