Web Hosting Talk







View Full Version : Command to zip up all contents within a directory?


GeorgeC
03-22-2002, 09:14 PM
Hi:
I'm trying to back up the contents of a certain directory. Problem is it contains literally hundreds of files, furthermore with subdirectories. Can someone tell me the command in telnet to zip up the entire folder, preferably with original permissions intact?

Thanks,

phpjames
03-22-2002, 09:27 PM
man tar

qdh
03-22-2002, 11:53 PM
Or, possibly a little more helpful than the above:

tar -cpzf filename.tar.gz *

GeorgeC
03-23-2002, 02:26 AM
Thanks qdh. I'm just reading up on tar.

I tried the command tar -cpzf filename.tar.gz *, and noticed it not only created the target tar file, but gz'd the participating files first. Is there any way to just create a tar file without tampering with the member files themselves, similar to Winzip in Windows?

Thanks,

bitserve
03-23-2002, 03:02 AM
It isn't gzipping each file and then adding it to the archive, it's gzipping the entire archive stream. This is explained in the man page.

If you don't want that, then do a tar without the -z.

RutRow
03-23-2002, 10:44 AM
tar -cpzf filename.tar.gz *

Please correct me if I am wrong, but I believe the 'p' option is for extraction only.

qdh
03-23-2002, 10:59 AM
RutRow:

I'm not 100% certain myself (about the -p switch) - I've always used it for both, to ensure that I retain the permissions on the files.

RutRow
03-23-2002, 12:27 PM
Yeah, it doesn't appear to give an error message either way. I do know that the Solaris boxes I use at work (man page) explicity state that it applies only when used with 'x'. My Linux man page just says 'extract all protection information'.

mkaufman
03-25-2002, 08:17 AM
tar -cvf /output/file.tar /dir/you/want/zipped

works perfectly

protector330
03-26-2002, 09:34 AM
zip -r directory directory

will create a directory.zip with all the stuff of /directory

first time I'm able to help somebody :D

bobcares
03-26-2002, 10:32 AM
Hi!
Say the directory is data and the file to be made is stored.zip. The command is

zip -9 -r stored.zip data

The -9 option gives maximum compression and the -r option goes in recursively.

Have a great day ... :)

Regards
Amar