Linux zforce Command Tutorial with Examples
The gzip command is a popular tool used for compressing/decompressing files in Linux. We've already covered the basics of this tool here. This utility produces .gz files in output. But sometimes - like while transferring files - the extension may get chopped off. You'll be glad to know there exists a tool that you can use to force the .gz extension back to these compressed files.
The tool in question is zforce, and in this tutorial, we will quickly discuss how you can use this command line utility. But before we jump on to that, it's worth mentioning that all examples here have been tested on an Ubuntu 18.04 LTS machine.
Linux zforce command
As already mentioned in the beginning, the zforce command allows you to force a '.gz' extension on all gzip files. Following is its syntax:
zforce [ name ... ]
And here's how the tool's man page explains it:
zforce forces a .gz extension on all gzip files so that gzip will not compress them twice.
This can be useful for files with names truncated after a file transfer. On systems with a 14 char
limitation on file names, the original name is truncated to make room for the .gz suffix.
For example, 12345678901234 is renamed to 12345678901.gz. A file name such as foo.tgz is left
For example, I have a .gz file named 'files'. As you can see, the extension .gz is missing from the name. So what I did, I simply used the following command:
And here's the output this command produced:
files -- replaced with files.gz
So you can see, the command output said it replaced 'files' with 'files.gz'. And when I checked for a .gz file in my current working directory, I could find a file named files.gz.
Now, if you have a directory full of .gz files whose names have been truncated, you don't have to provide each name in input. You can do something like I did in my case. Here it is:
So you can see all three files got the .gz extension. Rest assured that even if there are any files with .gz already in their name, this operation will leave them intact.
If you use gzip heavily and ever come across a situation where the .gz extension gets truncated from file names, now you know what to do. To access the man page for zforce, head here.