Web Hosting Talk







View Full Version : GZip on Linux?


a1022
09-08-2001, 07:36 AM
I'm a Newbie! :(

Okay i want to zip up a directory and all it's files and perserving it's tree structure into 1 file so that I can download it. Once I am done downloading it, I would like to upload it to another server and extract it there; again perserving it's tree structure.

What is the command syntax to compress it and decompressing it this way?

Would it perserve it's permission settings? Will it conflict with who owns what files on the new server?

Any help is greatly appreciated. Thanks!

Tim Greer
09-08-2001, 09:32 AM
I usually compress it like this:

tar cvf - directoryname | gzip -9 > directoryname.tar.gz

(You can remove the "v" in "cvf" if you don't want it to show you the files it's compressing -- I like to see it to make sure it's working correctly when adding files to compress).

And, I uncompress it like so:

gunzip directoryname.tar.gz | tar xvf -

Again, you can remove the "v" from "xvf" if you don't want it to show you the files it's decompressing -- but again, I like to know it's working correctly).

That will preserve the permissions. As for it preserving the ownership, that would depend on the user or UID/GID in the other server you uncompress this file on. Provided that's correct, it will preserve at least that. If you have none, it might just default to the UID/GID numbers. That's on the system, not in the file or what you compress, although it will be preserved if it's set up on the other server. Also, there's many ways to compress and decompress files and directories and entire directory tree's, and this is just one of many.

teck
09-08-2001, 12:27 PM
I usually just do the second part in one step:

tar -zxvf whatever.tar.gz

a1022
09-08-2001, 01:54 PM
Hey thanks Tim and Teck. I got it to compress... but the only problem is when I tried to uncompress it to the new server, it does it for awhile and then it says 'Killed' and then it stops... I figured it would be the user limit as the file is quite huge with more than 50,000+ small files.

So I tired to uncompress it under root. It worked but now all the files are under the owner '0' group '0' which I think is root user. The scripts won't run properly if the owner and group is under root and not the appropriate user name. :-(

Is there a way to change the owner of the files? If so can I do it all recursively and change all the files and dir under that tar to a different user name?

Thanks for all the help guys!

teck
09-08-2001, 02:09 PM
If you want to change ownership/group of the files and also recursively do it, as root, try:

chown user.group * -R

I think that works..I forgot what I did last time. You can also just do:

chown user.group directoryname -R

a1022
09-08-2001, 02:23 PM
Teck that did indeed changed the owner and group.. but my scripts still doesn't work for some strange reason.. it's giving me permission errors which gzip and tar should of preserved... Any ideas anyone?

teck
09-08-2001, 02:45 PM
You might want to:

chmod a+rx * -R

maxbear
09-08-2001, 05:10 PM
This article is really for you :cool:

http://lithos.gat.com/docview/tar_gzip.html

a1022
09-09-2001, 04:57 AM
Great! Everything works now. Thanks for all the help people. Especially to George (Eva2000) for taking time to personally assist me. :)

Man linux is one tough cookie. :D