Linux znew Command Tutorial for Beginners (with Examples)

How to Install Apache GUI on Ubuntu 18.04 LTS
How Setup and Configure Docker Swarm Cluster on Ubuntu
The Perfect Server – Ubuntu 18.04 (Nginx, MySQL, PHP, Postfix, BIND, Dovecot, Pure-FTPD and ISPConfig 3.1)

Did you know Linux offers a way to recompress .Z files to .gz files? Yes, the znew command lets you do this. In this tutorial, we will discuss the basics of this command line utility using some easy to understand examples. But before we do that, it’s worth mentioning that all examples here have been tested on an Ubuntu 18.04 LTS machine.

Linux znew command

As already mentioned above, the znew command in Linux lets you convert .Z files to .gz type by recompressing them. Following is its syntax:

znew [ -ftv9PK] [ name.Z …  ]

And here’s what the man page says about this command:

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.

Following are some Q&A styled examples that should give you a better idea on how the znew command works.

Q1. How to use the znew command?

It’s fairly simple – just provide the .Z file name as input. Here’s an example:

znew files2.Z

This command produces ‘files2.gz’ in the output, removing the original .Z file in the process.

Q2. What if a .gz file of same name already exists?

If a .gz file with the same name already exists in your current working directory, the znew command will ask to confirm whether or not you want to overwrite it.

For example, in my case, the following command:

znew files2.Z

produced the following confirmation prompt:

gzip: files2.gz already exists; do you wish to overwrite (y or n)?

So you can press ‘y’ if you want to move ahead, else press ‘n’. Alternatively, you can also use the -f command line option to force recompression from .Z to .gz format if a .gz file already exists.

Q3. How to make znew display details in output?

The -v command line option allows znew to display details like the name and percentage reduction for each file compressed. Here’s an example:

znew verbose output

Q4. What are other useful znew options?

There are a handful. Like -t tests the new files before deleting originals, -9 makes sure the tool uses the slowest compression method (optimal compression), and -P makes sure znew uses pipes for the conversion to reduce disk space usage.

Following is the complete list of options znew offers:

       -f     Force recompression from .Z to .gz format even if a .gz file already exists.

       -t     Tests the new files before deleting originals.

       -v     Verbose. Display the name and percentage reduction for each file compressed.

       -9     Use the slowest compression method (optimal compression).

       -P     Use pipes for the conversion to reduce disk space usage.

       -K     Keep a .Z file when it is smaller than the .gz file; implies -t.

Conclusion

If your work involves compressing and decompressing files through the Linux command line, the znew command may be useful to you. In this tutorial, we discussed some key options znew offers. For more info, head to the tool’s man page.

Himanshu Arora

About Himanshu Arora

Himanshu Arora has been working on Linux since 2007. He carries professional experience in system level programming, networking protocols, and command line. In addition to HowtoForge, Himanshu’s work has also been featured in some of world’s other leading publications including Computerworld, IBM DeveloperWorks, and Linux Journal.

Share this page:




COMMENTS