Skip to content
Advertisement

For zless to read empty gz file

I have tried to use zless to read (.gz) files.

zless $1.txt.gz

However, when (.gz) file is empty, it shows a message

"$1.txt.gz" may be a binary file.  See it anyway?

How to force zless to read an empty gz file without typing Y for many times.

or

Is that possible to return something like

$1 is empty 

Advertisement

Answer

zless is just a wrapper around less. You need to look at man less:

-f or –force Forces non-regular files to be opened. (A non-regular file is a directory or a device special file.) Also suppresses the warning message when a binary file is opened. By default, less will refuse to open non-regular files. Note that some operating systems will not allow directories to be read, even if -f is set.

The answer is

zless -f "${1}.txt.gz"
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement