How can I compress a number of files to a .tar.gz file using cygwin

niallo32
niallo32 used Ask the Experts™
on
I need to compress a number of files in XP into a .tar.gz file

Can anyone explain the steps to do so using cygwin?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
1. tar and gzip should be installed as a part of your Cygwin installation.
2. the command is like:
   tar -zcf c:/your-archive-file-name.tar.gz c:/path1-to-all-files "c:/path2 with space/fileXYZ.dat" c:/temp/mylog.txt
Alot depends on how your main drive is mapped in cygwin. Mine are mapped so that I can do things like cd /c to get to the root of the c drive. By default, if memoery serves me, it is mapped in this way:

/cygdrive/c for c drive
/cygdrive/d for d etc.

So let's assume you want to tar/gzip your documents (.doc) files in the "My Documents" folder.

tar -zcf ~/docs.tar.gz /cygdrive/c/Documents\ and\ Settings\username\My\ Documents\*.doc

The zcf means (z) compress using gzip, (c) create new archive and (f) filename of archive. The ~/ means to create the output file (docs.tar.gz) in your home folder in cygwin and the last portion of the command is what files do you want to add to the archive. You can add as many file paths, files and folders here as you like on the single command line.

If you want to see which files go into the archive as it is working replace zcf with zcvf for verbose output.

To decompress, use tar -xf docs.tar.gz or xvf for verbose output.

Cheers,

Lee

Kerem ERSOYPresident

Commented:
You can also create compressed archives using the z switch as such:

tar -cvzf /cygwin/c/Documents and Settings/user/compressed.tar.gz   /cygwin/c/path

to create an compressed archive.

then to reopn the archive you can use:

tar xvzf /cygwin/c/Documents and Settings/user/compressed.tar.gz

GNU tar will remove the beginning "/" during decompress so it will ope the archive relative to the current path. So if you want to restore /cygwin/c/path to the same folder then you need to be at /cygwin/c or otherwise files will be restore relative to current path. Not the root itself.

Cheers,
K.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial