How to use the command znew (with examples)
The znew
command is used to recompress files from .Z
to .gz
format. This can be useful when you need to convert files compressed using the outdated .Z
format to the more modern .gz
format. The command provides options for achieving different levels of compression and for keeping the original .Z
file if it is smaller than the resulting .gz
file.
Use case 1: Recompress a file from .Z
to .gz
format
Code:
znew path/to/file1.Z
Motivation: This use case is useful if you have a single file compressed in the .Z
format and you want to convert it to the .gz
format.
Explanation: The command znew
is followed by the path to the .Z
file that you want to recompress. In this use case, the command is run with just the path to the file, which tells znew
to recompress the file without any additional options.
Example output:
file1.Z: 99.9% -- replaced with file1.gz
In this example, the file file1.Z
is successfully recompressed to file1.gz
, and the achieved size reduction is displayed as 99.9%.
Use case 2: Recompress multiple files and display the achieved size reduction % per file
Code:
znew -v path/to/file1.Z path/to/file2.Z path/to/file3.Z
Motivation: This use case is helpful when you have multiple files compressed in the .Z
format and you want to convert all of them to the .gz
format. Additionally, the -v
option allows you to see the achieved size reduction percentage for each file.
Explanation: The -v
option stands for “verbose” and it tells znew
to display the achieved size reduction percentage for each file that is recompressed. The command is followed by the paths to the .Z
files that you want to recompress.
Example output:
path/to/file1.Z: 99.9% -- replaced with file1.gz
path/to/file2.Z: 90.2% -- replaced with file2.gz
path/to/file3.Z: 98.5% -- replaced with file3.gz
In this example, three files file1.Z
, file2.Z
, and file3.Z
are recompressed to .gz
format, and the achieved size reduction percentages for each file are displayed.
Use case 3: Recompress a file using the slowest compression method (for optimal compression)
Code:
znew -9 path/to/file1.Z
Motivation: This use case is beneficial if you prioritize the highest level of compression and are willing to trade processing time for smaller compressed file sizes.
Explanation: The -9
option tells znew
to use the slowest compression method available, which typically achieves the highest level of compression. The command is followed by the path to the .Z
file that you want to recompress.
Example output:
file1.Z: 99.9% -- replaced with file1.gz
In this example, file1.Z
is recompressed with the slowest compression method, resulting in the highest level of compression and a significant size reduction.
Use case 4: Recompress a file, keeping the .Z
file if it is smaller than the .gz
file
Code:
znew -K path/to/file1.Z
Motivation: This use case is useful when you want to replace the original .Z
file with the recompressed .gz
file unless the .Z
file is smaller than the resulting .gz
file. In this case, you can choose to keep the original file.
Explanation: The -K
option stands for “Keep” and it tells znew
to retain the original .Z
file if it is smaller than the resulting .gz
file. The command is followed by the path to the .Z
file that you want to recompress.
Example output:
file1.Z: 99.9% -- replaced with file1.gz
In this example, file1.Z
is recompressed to .gz
format, and the original file is replaced with the recompressed file because the size reduction achieved is 99.9%, rendering the new file smaller than the original.
Conclusion:
The znew
command provides a simple way to recompress files from .Z
to .gz
format. By using various options like -v
, -9
, and -K
, you can control the compression level, view the achieved size reduction percentages, and choose to keep the original file under certain conditions. This command is especially useful for converting files compressed using the outdated .Z
format to the more modern .gz
format.