Operating System - HP-UX
1751685 Members
5041 Online
108781 Solutions
New Discussion юеВ

how to zip / compress a directory ?

 
SOLVED
Go to solution
ng_7
Regular Advisor

how to zip / compress a directory ?

hi, appreciate if someone could provide me command to compress / zip a unix directory.

thanks
14 REPLIES 14
Steven E. Protter
Exalted Contributor

Re: how to zip / compress a directory ?

Shalom

tar cvf /tmp/tarfile.tar /directory/

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dennis Handly
Acclaimed Contributor
Solution

Re: how to zip / compress a directory ?

>SEP: tar cvf /tmp/tarfile.tar /directory/

After this, you can gzip or compress tarfile.tar. Of course you can do it in one step with a pipe.
Hemmetter
Esteemed Contributor

Re: how to zip / compress a directory ?

Hi ng,

You can't compress a directory.
You can compress/gzip the files inside:

$ cd /dir ; compress *

or as Steven suggested you can create a archive of the directory

$ tar cvf dir.tar /dir
or compressed:
$ tar cvf - /dir | compress >dir.tar.Z


see compress(1), gzip(1)

rgds
HGH



Yogeeraj_1
Honored Contributor

Re: how to zip / compress a directory ?

hi,

using the default software on the OS, you can easily achieve this using two steps.

Step 1. Archive files together
tar -cvf /tmp/DIR1.TAR ./

Step 2. Compress them together
gzip -S .Z /tmp/DIR1.TAR

You should also be aware of absolute/relative path issues.


hope this helps too!
kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Reshma Malusare
Trusted Contributor

Re: how to zip / compress a directory ?

Hi ng,
1> compress
The compress utility will attempt to reduce the size of the named files by using adaptive Lempel-Ziv coding. Except when
the output is to the standard output, each file will be replaced by one with the extension .Z, while keeping the
same ownership modes, change times and modification times.

compress [-fv] [ -b bits ] [ file ]
compress [-cfv] [ -b bits ] [ file ]

2>gzip
Gzip reduces the size of the named files using Lempel-Ziv coding (LZ77). Whenever possible, each file is replaced by one with the extension .gz, while keeping the same ownership modes,access and modification times.By default, gzip keeps the original file name and timestamp in the compressed file.

gzip [ -acdfhlLnNrtvV19 ] [-S suffix] [ name ... ]

3> tar

Mentioned above

Thanks & Regards
Reshma Malusare

Re: how to zip / compress a directory ?

Most of the time, compress command is not a good option. I would prefer to choose tar followed by gzip, as some of them mentioned in this forum.
Your imagination is the preview of your life's coming attractions
Dennis Handly
Acclaimed Contributor

Re: how to zip / compress a directory ?

I just noticed there is a compressdir(1) command.
Steven Schweda
Honored Contributor

Re: how to zip / compress a directory ?

As usual, the answer depends on missing
information. For example: Why?

If you intend to transfer the files to a
non-UNIX system, then the Info-ZIP [Un]Zip
programs would probably make more sense. If
you're just trying to save some space on your
HP-UX system, of if you intend to transfer
the files to another UNIX system, then a
"tar" pipeline into gzip or bzip2 would
probably make more sense.

For a complete (and useful) answer, ask a
complete question.
ng_7
Regular Advisor

Re: how to zip / compress a directory ?

thanks everyone for help, and i am interested in compressdir, can please tell me after compressdir, how do we uncompress it ? thanks