zless

file_compressionlinux
The zless command is one of the most frequently used commands in Linux/Unix-like operating systems. zless View compressed files with the less pager

Quick Reference

Command Name:

zless

Category:

file_compression

Platform:

linux

Basic Usage:

zless [options] [arguments]

Common Use Cases

    Syntax

    zless [options] file...

    Options

    ## Common Options zless accepts all options supported by the less command: | Option | Description | |--------|-------------| | -e, --quit-at-eof | Exit when reaching end of file | | -E, --QUIT-AT-EOF | Exit when reaching second end of file | | -F, --quit-if-one-screen | Exit if entire file fits on first screen | | -i, --ignore-case | Ignore case in searches | | -I, --IGNORE-CASE | Ignore case in searches and patterns | | -m, --long-prompt | Show more verbose prompt | | -M, --LONG-PROMPT | Show even more verbose prompt | | -n, --line-numbers | Don't display line numbers | | -N, --LINE-NUMBERS | Display line numbers | | -p, --pattern=pattern | Start at pattern (from command line) | | -P, --prompt=prompt | Define new prompt | | -q, --quiet | Quiet mode (no bell) | | -Q, --QUIET | Even quieter mode | | -r, --raw-control-chars | Display raw control characters | | -s, --squeeze-blank-lines | Squeeze multiple blank lines into one | | -S, --chop-long-lines | Chop long lines rather than wrapping | | -x, --tabs=n | Set tab stops | | -X, --no-init | Don't use termcap init/deinit strings | | --no-keypad | Don't use termcap keypad init/deinit strings | For a complete list of options, see the less(1) manual page.

    Examples

    How to Use These Examples

    The examples below show common ways to use the zless command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    # View a compressed file with zless zless logfile.gz
    # View multiple compressed files zless file1.gz file2.gz file3.gz
    # Advanced Examples Advanced
    # Use search functionality within zless (press / to search) zless large_log.gz # Then type '/error' and press Enter to search for 'error'
    # Navigate to a specific line number (press : to enter command mode) zless huge_file.gz # Then type ':100' and press Enter to go to line 100
    # Show line numbers in zless (press -N to toggle) zless -N config.gz # View a compressed file with custom options passed to less zless -S datafile.gz # Chop long lines instead of wrapping # View a compressed file with case-insensitive search LESS='-i' zless logfile.gz # Pipe grep output to zless for easier viewing of long results zgrep -A 10 "ERROR" *.log.gz | zless # Use zless with marks to navigate between positions zless data.gz # Press m followed by a letter to set a mark # Press ' followed by the same letter to return to that mark

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    ## Important Notes - zless is a shell script that invokes less on compressed files. - zless automatically detects and handles various compression formats including gzip, bzip2, xz, and others. - Most interactive commands available in less are also available in zless. - The environment variable LESS can be set to provide default options to less. - Unlike zcat, zless provides interactive viewing, allowing you to scroll, search, and navigate through the file. - zless does not decompress the file on disk; it decompresses on-the-fly for viewing. - When viewing multiple files, you can switch between them using :n (next file) and :p (previous file). - Marks set in zless are not saved between sessions. - zless is especially useful for viewing large compressed log files without using disk space for decompression. ## Common Interactive Commands (once inside zless) - Space or f: Forward one window - b: Backward one window - g: Go to first line - G: Go to last line - /pattern: Search forward for pattern - ?pattern: Search backward for pattern - n: Repeat previous search - N: Repeat previous search in reverse direction - q: Quit zless

    Related Commands

    These commands are frequently used alongside zless or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the zless command works in different scenarios.

    $ zless
    View All Commands