cancel
Showing results for 
Search instead for 
Did you mean: 

gzip append to a file

ivy1234
Frequent Advisor

gzip append to a file

I have many files in a folder , I want to gzip this files into a existing gzipped file ( I will do the gzip time by time , not gzip the files in a batch )

For example

I gzip the file aa.txt to file.gz , after 1 hour , I will gzip another file bb.txt to file.gz , 2 minutes later , I will gzip the file cc.txt to file.gz ...

I know tar can do that , can advise if gzip can also do that ?

Thanks
9 REPLIES
RickT_1
Valued Contributor

Re: gzip append to a file

Hello Ivy,

according to the man page all you would have to do is compress the files you want and then append them together, like this:

gzip -c file1 > foo.gz
gzip -c file2 >> foo.gz


Rick
Steven Schweda
Honored Contributor

Re: gzip append to a file

> according to the man page [...]

According to _what_ on which "man" page? Did
you try this? (Where "try this" includes
trying to recover the original files.) Did
it work?

When I tried it, the result was a
concatenation of the original files, not a
set of files like the original files. For
example:

dyi # ls -l ../*t.c
-rw-r--r-- 1 root sys 142 Nov 1 2008 ../cst.c
-rw-r--r-- 1 root sys 234 Oct 27 06:28 ../rt.c

dyi # rm *

dyi # ( cd .. ; gzip -c cst.c ) > fred.gz
dyi # ( cd .. ; gzip -c rt.c ) >> fred.gz

dyi # ls -l
total 16
-rw-r--r-- 1 root sys 314 Apr 13 22:20 fred.gz

dyi # gzip -dN fred.gz

dyi # ls -l
total 16
-rw-r--r-- 1 root sys 376 Oct 27 06:28 cst.c
dyi #

(Note that 142 + 234 = 376.)


> I know tar can do that, [...]

You know that "tar" can do what, exactly?
(As usual, a demonstration would be a good
way to explain that.)


If I understand the request correctly, then
a program like Info-ZIP Zip may be suitable.

dyi # rm *

dyi # pwd
/root/itrc/gzipt

dyi # ( cd .. ; zip gzipt/fred.zip cst.c )
adding: cst.c (deflated 15%)

dyi # ( cd .. ; zip gzipt/fred.zip rt.c )
adding: rt.c (deflated 37%)

dyi # unzip fred.zip
Archive: fred.zip
inflating: cst.c
inflating: rt.c

dyi # ls -l
total 48
-rw-r--r-- 1 root sys 142 Nov 1 2008 cst.c
-rw-r--r-- 1 root sys 563 Apr 13 22:26 fred.zip
-rw-r--r-- 1 root sys 234 Oct 27 06:28 rt.c

Zip is a more comprehensive archiving utility
than "gzip". (And it compresses better than
plain "tar".) It's intended to be able to
put multiple input files into one archive,
possibly at different times. (Its archives
include a kind of "table of contents", which
it updates when it adds a new file to an
existing archive.) If gzip can do anything
like that, then it's news to me.

For the record:

dyi # uname -a
HP-UX dyi B.11.31 U ia64 4235313755 unlimited-user license

dyi # zip -v
Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
This is Zip 3.0 (July 5th 2008), by Info-ZIP.
[...]

dyi # unzip -v
UnZip 6.00 of 20 April 2009, by Info-ZIP. Maintained by C. Spieler. Send
[...]

http://www.info-zip.org/
Mel Burslan
Honored Contributor

Re: gzip append to a file

As far as I know, gzip is a mere compression utility not an archiving tool like winzip or similar. It is up to the end use to archive using likes of tar and then gzip the whole file in one pass.

to aapend to gzip,

gunzip
append
gzip

is the only way I know.
________________________________
UNIX because I majored in cryptology...
ivy1234
Frequent Advisor

Re: gzip append to a file

thx reply ,

I tried parameter -c , but I found that the data will be append to the previous file , when I extract the zipped file , all data will be conbined into one single file .

If I only want the file append to previous file eg. if I append 10 files to it , the output should be 10 files , what can i do ? Thanks
Steven Schweda
Honored Contributor

Re: gzip append to a file

> [...] what can i do ? [...]

Use Zip instead of gzip?

Did you read these replies?
ivy1234
Frequent Advisor

Re: gzip append to a file

Thx reply ,

because the server do not have zip package , we do not want to install package to it ( because some reasons ), so we want to use gzip.

Thanks,
Steven Schweda
Honored Contributor

Re: gzip append to a file

> because the server do not have zip package ,

That's pretty easy to fix.

> we do not want to install package to it
> ( because some reasons ),

Any _good_ reasons?

> so we want to use gzip.

If you want to use gzip, then don't let me
stop you. I want gzip to fill my pockets
with gold coins, but I suspect that gzip
can't do that, either.

I'll tell you what. If I find a way to get
gzip to do what you want, I'll let you know.
If you find a way to get it to do what _I_
want, you let me know. I won't be holding my
breath. You probably shouldn't be holding
yours, either.
Dennis Handly
Acclaimed Contributor

Re: gzip append to a file

>so we want to use gzip.

Then you'll need to continually gunzip a tar add to the tar and gzip.

While gnu tar has a -z option, I'm not sure if it allows to to append when you use -z?
Steven Schweda
Honored Contributor

Re: gzip append to a file

> While gnu tar has a -z option, I'm not sure
> if it allows to to append when you use -z?

http://www.gnu.org/software/tar/manual/
http://www.gnu.org/software/tar/manual/html_node/gzip.html

[...]
Notice also, that there are several
restrictions on operations on compressed
archives. First of all, compressed archives
cannot be modified, i.e., you cannot update
('--update', alias '-u') them or delete
('--delete') members from them or add
('--append', alias '-r') members to them.
Likewise, you cannot append another tar
archive to a compressed archive using
'--concatenate' ('-A'). Secondly,
multi-volume archives cannot be compressed.
[...]