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.
there are lots of compression methods that work recursively command line and its good to know who the end audience is.
i.e. if it is to be sent to someone running windows then zip would probably be best:
for other linux users or your self tar is great
One must be careful with tar and how things are tarred up/extracted, for example if I run
/home/myusername
this will create /home/myusername/etc/passwd
unsure if all versions of tar do this:
@amitchhajer 's post works for GNU tar. If someone finds this post and needs it to work on a NON
GNU
system, they can do this:To expand the archive:
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