Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use znew command in Terminal to recompress files UNIX
A recent "tip of the day" from Unix Guru Universe noted:
In HP Unix, the compress command will compress around 50 to 60%. gzip will compress the file up to 80%. There is a command available in HP's unix to convert a compress file to a zip file. znew will automatically convert compressed files (*.Z) to gunzip files (*.gz).
I wondered if this existed under OS X and by doing a which znew, I found that it does indeed exist under /usr/bin/znew. The man page states, "Znew recompresses files from .Z (compress) format to .gz (gzip) format. If you want to recompress a file already in gzip format, rename the file to force a .Z extension then apply znew." What a handy little program!
    •    
  • Currently 2.00 / 5
  You rated: 4 / 5 (5 votes cast)
 
[10,337 views]  

Use znew command in Terminal to recompress files | 9 comments | Create New Account
Click here to return to the 'Use znew command in Terminal to recompress files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use znew command in Terminal to recompress files
Authored by: geohar on Apr 19, '04 11:39:02AM
link is broken: should be http://www.ugu.com

[ Reply to This | # ]
Use znew command in Terminal to recompress files
Authored by: jreades on Apr 19, '04 02:17:55PM
I did a quick test and you should be able to get away with the following:

uncompress -c foo.txt.Z | gzip -c > bar.txt.gz
Not quite so friendly as a command, but it get the job done quite nicely. Note that it will only work for single files. You might be able to handle multiple files using tar but I certainly wouldn't count on it. jon

[ Reply to This | # ]
ditto
Authored by: SeanAhern on Apr 19, '04 02:41:53PM
This script should do the trick:
#!/bin/sh
for file do
    uncompress -c $file | gzip -c > ${file%%.Z}.gz
done
Now, the actual znew script is also just a Bourne shell script, so this really isn't saying much. The real znew script has error recovery, testing of output files, changes to compression level, etc.

I include my script here merely to show that there's no magic here. It's actually a fairly simple formula.

[ Reply to This | # ]

ditto
Authored by: LC on Apr 19, '04 05:32:42PM
Bourne sh wouldn't do the pattern substitution though;
(but bash sh, ksh, zsh do do it)

gzip -dc $file | gzip -c > ${file%%.Z}.gz || echo "ERROR -- Couldn't make '${file%%.Z}.gz'"

[ Reply to This | # ]
Use znew command in Terminal to recompress files
Authored by: EddEdmondson on Apr 19, '04 05:52:53PM

If you're recompressing to get a better ratio then consider bzip2 instead. It's slower, but better at compressing than gzip.



[ Reply to This | # ]
Use znew command in Terminal to recompress files
Authored by: forman on Apr 19, '04 08:50:45PM
As posted in an above thread, the command

uncompress -c file.Z | gzip -c > file.gz

will do the same thing as the znew command.

What it omits is that it will perform it twice as fast on a dual-processor machine. Apparently, znew performs the decompression and compression in a serial manner. The use of a pipe ("|"), however, will execute the programs in parallel. Thus on a dual-processor machine, the conversion process will take half the time. Give it a try and see!

Michael.

[ Reply to This | # ]
Use znew command in Terminal to recompress files
Authored by: wgscott on Apr 19, '04 09:35:55PM

You can read the program as it is a shell script, and the -P option does what you suggest.



[ Reply to This | # ]
Use znew command in Terminal to recompress files
Authored by: forman on Apr 20, '04 02:00:56AM

You can tell I'm on a MacOS website.

Your response should have been "RTFM". :)

Michael.

[ Reply to This | # ]
bzip2
Authored by: krid2000 on Apr 20, '04 07:50:51AM

bzip2 compresses even better than gzip and is a kind of standard for modern linux distributions. It's a drop-in replacement for gzip.



[ Reply to This | # ]