Operating System - HP-UX
1752600 Members
4326 Online
108788 Solutions
New Discussion юеВ

Re: How to compress entire directory and it's subs

 
Becke
Super Advisor

How to compress entire directory and it's subs


Dear Guys

How do I compress entire directory including it's subs, dba's would like to compressed/zip in tar ball of this huge logs directory so they can upload it to their support online..

I want to use tar command to zip all of this, or perhaps gzip utility,,,can u pls let me know the correct syntax and command..

so for e.g I want to compress /frog directory and all of it's contents and place a zip ball into destination /somefilesystem ?

Thanks in Advance
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor

Re: How to compress entire directory and it's subs

Hi:

# cd /path
# tar -cvf /var/tmp/myarchive.tar ./mystuff
# gzip /var/tmp/myarchive.tar

This gives you '/tmp/myarchive.tar.gz' which is a compressed archive of the './mystuff' directory and all its contents.

Regards!

...JRF...
Victor Fridyev
Honored Contributor

Re: How to compress entire directory and it's subs

In addition to the previous recommendation, which is fully correct.
If you want to omit intermidiate file creation, the command may look as follows:
tar -cvf - PATH_TO_LOG_DIRECTORY| gzip > rezfile.tar.gz
Entities are not to be multiplied beyond necessity - RTFM
Laurent Menase
Honored Contributor

Re: How to compress entire directory and it's subs

if you don't test the result of tar and gzip, - which is advised, you can
# cd /path
# tar cvf - ./mystuff |gzip >/var/tmp/myarchive.tar.gz

or use gnu tar and use tar cvzf /var/tmp/myarch.tgz ./mystuff
Steven Schweda
Honored Contributor

Re: How to compress entire directory and it's subs

> # tar -cvf /var/tmp/myarchive.tar ./mystuff
> # gzip /var/tmp/myarchive.tar

Or using the latest "pipeline" technology:

tar cf - ./mystuff | \
gzip > /var/tmp/myarchive.tar


> I want to use tar command to zip all of
> this, or perhaps gzip utility,,,

It might help if you explained what you wish
to do, rather than how you wish to do it.
"tar" collects files, but does not itself
compress. If the people receiving the file
are not using a UNIX(-like) system, then Zip
might be a better choice than tar+gzip.


> [...] it's subs [...]
> [...] it's contents [...]

"its".

> [...] for e.g [...]

"e.g." or "for example".
Becke
Super Advisor

Re: How to compress entire directory and it's subs


Thanks Team I've got what I wanted,

By the way tar command will tar all the subdirectories and their contents as well rite?

James R. Ferguson
Acclaimed Contributor

Re: How to compress entire directory and it's subs

Hi (again):

> By the way tar command will tar all the subdirectories and their contents as well rite?

Yes.

In fact, you can answer this yourself with a simple test :-)

Regards!

...JRF...