How to use the command 'zless' (with examples)
The zless
command is used to view the contents of compressed files. It is specifically designed to handle the gzip
and xz
compression formats. By using zless
, users can easily view the contents of compressed files without having to manually decompress them first.
Use case 1: Page through a gzip
compressed file with less
Code:
zless file.txt.gz
Motivation:
The motivation for using this example is to be able to quickly view the contents of a gzip
compressed file in a convenient manner. By using zless
, there is no need to manually decompress the file before being able to read its contents.
Explanation:
The command zless file.txt.gz
is used to view the contents of a gzip
compressed file called “file.txt.gz”. The zless
command acts as a filter, decompressing the file on-the-fly and then passing the decompressed content to the less
command for paging.
Example output:
This is an example text file.
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nullam lacinia hendrerit quam in sollicitudin.
Donec congue ipsum at viverra consectetur.
In this example, zless
decompresses the file.txt.gz
file and displays its contents. The user can then scroll through the file using the same keybindings as the less
command.